TestNG
I have mostly been using junit for writing Java unit tests but lately took a quick look at TestNG.
I created a IBAN validator class. Depending on the country the IBAN number needs specific validation.
IBAN_REGEX holds a regular expression defining valid IBAN numbers. The validate() method matches the IBAN number against the regular expression and passes back true or false.
The following test is the accompanying TestNG test.
The dataproviders (correctNumbers and incorrectNumbers) hold an array of correct and incorrect IBAN numbers. These get passed into the validateCorrectNumbers and validateIncorrectNumbers test methods.
The method setUp() will be invoked before any test method is run. There is no need to extend a class or implement an interface. A test method can belong to one or several groups. I did not use groups here though but it is a nice feature to use.
To get the full working version of this test clone repository https://github.com/wwillems/techlogprojects.git Go to techlogprojects/testng and run mvn clean install
blog comments powered by Disqus