The new version of TestNG was released. Cedric made the first announcement and the news spreaded quite fast.
The main addition in the new version are the completely revamped annotations. The old @Configuration was replaced by more clear and much more readable annotations: @Before/AfterSuite
, @Before/AfterTest
, @Before/AfterGroup
, @Before/AfterClass
, @Before/AfterMethod
(phewww… quite a few). But check the following code to see how much better it is:
The “old” way:
public class MethodCallOrderTest { @Configuration(beforeTestClass=true) public void beforeClass() { // do before any test methods in this class are executed } @Configuration(beforeTestMethod=true) public void beforeMethod() { // do before each test method } @Test public void realTest() { } @Configuration(afterTestMethod=true) public void afterMethod() { // do after each test method } @Configuration(afterTestClass=true) public void afterClass() { } @Configuration(afterSuite=true) public void cleanUp() { // do once after all tests } }
new way:
public class MethodCallOrderTest { @BeforeClass public void beforeClass() { // hey it looks like I don't need to put any comment here to explain it, ain't it? } @BeforeMethod public void beforeMethod() { } @Test public void realTest() { } @AfterMethod public void afterMethod() { } @AfterClass public void afterClass() { } @AfterSuite public void cleanUp() { } }
There are a lot more improvements in this new version: better reports, filtered stack traces, more configuration options for the Ant task.
Last, but not least: don’t worry about the next versions. We already have in mind a couple of more nice things that will make life easier and a lot more pleasant for test developers.
Does TestNG have a web interface for running tests interactively, like JunitEE?
Hi Corby,
It’s something I’ve had on my mind for quite a while but since nobody seemed to be that interested, I didn’t investigate the idea further. Please email testng-users@googlegroups.com with your suggestion and maybe a few directions on how you would use such a feature?
Thanks!
—
Cedric
Alexandru –
After having issues migrating to TestNG 5 from 4.7, I looked at your sample code some more. I point print statements in each method from your example, ran both test classes, and got different outputs – the old way working as expected, the new way not running any of the before/after code.
Do you see the same thing?
Argh – that’s what happens when I rely on version 4.7 of the Eclipse plugin…
A word to the wise – if you’re using an Eclipse or Intellij plugin – do an update there too!