Quantcast
Channel: Java Team at Kentor » Frameworks
Viewing all articles
Browse latest Browse all 26

TestNG(Next Generation) a unit testing framework

$
0
0

There might be other unit testing frameworks available which maybe better than TestNG but for me coming from a JUnit test framework background it was easy to adapt to TestNG (which has got inspiration from JUnit and NUnit). The requirement I had was to have a test framework where it was:

  • Easy to pass data as parameters to the test from a resource file

<test name=”testElement”>
<classes>
<class>
<parameter name=”element” value=”LKG”/>
</class>
</classes>
</test>

@Parameters(value= {“element”})
@Test
public void testElement(String element) {

//same Assert statements as in JUnit

}

  • Easy to configure in a big project (one resource file for each corresponding  Test File) and the main Suite to run all the tests

<suite name=”MainTestSuite”>
<suite-files>
kentor/TestElement.xml” />
</suite-files>
</suite>

  • Do things that I could do with JUnit like testing expected exceptions

@Test(expectedExceptions = ArithmeticException.class)
public void divisionWithZeroException() {
int i = 1/0;
}

  • IDE Support (Eclipse, Netbeans). Inbuilt in Netbeans latest versions.
  • Generating various types of reports
  • Integrating with Maven and few more…

It is only a matter of starting to use TestNG and you would know how ease it is to write Unit test with this library. More could be read on the documentation  where a lot is talked about grouping the tests, using DataProviders (instead of parameter passing), running test parallel, Creating factory classes and reporting



Viewing all articles
Browse latest Browse all 26

Trending Articles