Monday, 29 October 2012

Implementing TestNG

I'm starting with a Selenium test framework which I have hammered together over the last few weeks which involves Selenium + Junit, all written in Java and with the help of Eclipse. There are now a few tests performing over 300 validations, and now I am starting to realize that maybe driving my tests through JUnit is just not good enough. 

The immediate issues I am aiming to resolve is the ability to tag and execute specific tests, report tests as being 'not run' (rather than passed/failed) and get some cool xml reporting going on. From a skim through of the TestNG stuff it looks like that's going to make my life easier. 

So, what to do. 

Using TestNG in your code (for Java)

Get TestNG jar
2) save/extract somewhere

In your project/build tool
3) configure your project's build path to include the TestNG Jar

In your code
4) Remove your JUnit references, just to force us in to importing/using TestNG's stuff
//import org.junit.*;
5) Add in references to TestNG
import org.testng.annotations.Test;
import org.testng.Assert;
6) replace your JUnit assert(..., ...) commands with Assert.assert(..., ...)

Please note, TestNG goes
Assert.assertEquals(actual, expected)
rather than expected, actual. 

Driving TestNG with eclipse

Get Eclipse/TestNG plugin (offline download)
And the link to download the plugin (not necessarily the most up to date, but at least a working one) is here: https://groups.google.com/forum/?fromgroups=#!topic/testng-users/v8mlca9oQoo
With this I have simply placed the .jar in my eclipse plug in dir (e.g. C:\dev\eclipse\plugins) and the started Eclipse, and I seem to have gained the ability to run TestNG tests. 

And now the TestNG plug in / program runner is available within the Debug As and Run As context menu options. 

Alternative / Eclipse's easy as 'Install' feature
You can do this cool thing where you download and install the software by going Help > Install new Software > and then chose TestNG from http://beust.com/eclipse
I work under archaic, fear based corporate policies however, and so this option is not available to me. 



No comments:

Post a Comment

Robot Framework, Basic Setup

Plug: Robot Framework is quick to setup, easy to write tests for, and super fast to triage failures in. The last point really sets it apart...