namalfernandolk
namalfernandolk

Reputation: 9134

Advantage of using @Test(enabled = false) over the commenting @Test annotation in TestNG

I know that @Test(enabled = false) will ignore the test for the annotated method.
But why can't we just Comment the annotation to ignore.

I mean what is the advantage of using @Test(enabled = false) over the commenting @Test annotation?

Upvotes: 3

Views: 684

Answers (1)

MariuszS
MariuszS

Reputation: 31595

The only difference is related to programming style.

Commenting source code is commonly recognized as violation. Commented code should be removed from source code.

There is violation Avoid commented-out lines of code in Sonarqube with nice description

Here are the main reasons why commented code is a code smell :

  • It always raises more questions than it gives answers
  • Everybody will forget very quickly how relevant the commented code is
  • This is distraction when going down the code as it stops the flow of eyes
  • It is a bad SCM engine : Subversion, CVS and Git are really more trustworthy !
  • The simple fact of understanding why code was commented out in the first place can take a lot of time

Example real case: Code cleanup: remove commented out code

Upvotes: 5

Related Questions