First impressions though is that the TestNG features you mentioned (not a library I am vary familiar with) are offered by JUnit as well.
The dataprovider annotation seems analogous to JUnit's @RunWith(Parameterized.class) annotation. And the expectedExceptions similarly analogous to JUnit's @Test(expected=Exception.class) annotation.
All said, would be interested to hear if there are subtle differences here, or perhaps a future article on some more powerful features of TestNG.
I am quite happy to see you finally mentioning TestNG!
@ben: in fact there is a very big difference between JUnit @RunWith(Parameterized) and TestNG data providers. JUnit parameterized approach is just able to pass parameter to your test instance through constructor parameters. So, basically you are restricted to use a single data source per test class. TestNG data providers are feeding parameters directly to @Test methods, so you can have as many data sources per test class. There are more subtle differences like the test class instantiation model which is different (and sometimes considering that some data sources are expensive may lead to expensive tests). Also TestNG support eager and lazy data providers (I am not sure if the later is available in JUnit.
Regarding the expectedException: TestNG was created before JUnit4, so I was glad to see this feature (as a couple of others) getting picked by the JUnit team.
Nice short TotT article.
ReplyDeleteFirst impressions though is that the TestNG features you mentioned (not a library I am vary familiar with) are offered by JUnit as well.
The dataprovider annotation seems analogous to JUnit's @RunWith(Parameterized.class) annotation. And the expectedExceptions similarly analogous to JUnit's @Test(expected=Exception.class) annotation.
All said, would be interested to hear if there are subtle differences here, or perhaps a future article on some more powerful features of TestNG.
PHPUnit also supports a @dataProvider annotation (and quite some other annotations, for instance to get more meaningful code coverage information).
ReplyDeleteI am quite happy to see you finally mentioning TestNG!
ReplyDelete@ben: in fact there is a very big difference between JUnit @RunWith(Parameterized) and TestNG data providers. JUnit parameterized approach is just able to pass parameter to your test instance through constructor parameters. So, basically you are restricted to use a single data source per test class. TestNG data providers are feeding parameters directly to @Test methods, so you can have as many data sources per test class.
There are more subtle differences like the test class instantiation model which is different (and sometimes considering that some data sources are expensive may lead to expensive tests). Also TestNG support eager and lazy data providers (I am not sure if the later is available in JUnit.
Regarding the expectedException: TestNG was created before JUnit4, so I was glad to see this feature (as a couple of others) getting picked by the JUnit team.
cheers,
./alex
--
.w( the_mindstorm )p.
TestNG co-founder
EclipseTestNG Creator
Actually, this looks much more like with @Theory introduced on JUnit 4.4. It was an addition made from Popper library.
ReplyDeletehttp://junit.sourceforge.net/doc/ReleaseNotes4.4.html#theories