Subtitled “TestNG and Advanced Concepts” and written by the people behind TestNG, I picked up this book expecting to read a definitive and encyclopedic work on TestNG. However, the authors decry this view in the preface. This book takes ‘testing’ as its focus and uses TestNG to illustrate the examples. (Although it does really start off as “a book about TestNG”).
So prior to reading the book my experience of TestNG amounted to the following:
- read some of the tests people had written using TestNG at work
- amended some of the tests
- hacked about with the testng.xml file
- fixed some tests
- gone to the website to learn a little more about some of the annotations and the xml file
- Read, and used, the examples on the home page
- Run tests and suites within Eclipse
- Skimmed the documentation
So, as a beginner I felt like I could already ‘use’ TestNG, but I didn’t really understand some of the concepts ‘properly’ like dataproviders - sure I could write one, but I didn’t really ‘get’ all the nuances. Hence the reason for reading this book.
And I had learned the hard way that TestNG does not view the method that you annotate with @Test as a ‘test’ . TestNG views a test as that thing in the testng.xml file with
So we start by learning a little about the deficiencies in JUnit that led to the creation of TestNG - to support different styles of testing and more ‘functional’ testing. Then a few examples of the annotations and the testng.xml file.
Then into unit testing with TestNG and testing exceptions.
I learned that TestNG creates a testng-failed.xml file containing a suite of just the failing tests. Which I hadn’t noticed when skimming the docs online. But I can quite clearly see it in section 5.10 online now.
Then we jump straight into Factories. Whoa! Sub-optimal organisation for the beginner. I think the early parts of the book help argue the case for ‘another unit test framework’ and make you ask the question ‘can your unit test framework do this?’
I say this because we have a test suite running quite well at work using just
So, still a bit bemused, factory only takes 4 pages, then we move on to the official section on Data-Driven Testing and this does seem written more with the beginnner in mind - why try and scare me off with a Factory example?
The data providers in TestNG really have a lot of power.
In some ways TestNG has too much power because you move from simple example to complex example within the same breath and having just figured out why you might use a data provider you have to wrap your head around how you might use the test context functionality.
OK, so not again, definitely not structured with the beginner in mind. And as a beginner you end up skipping chunks to get what you need. And when you finally try it in your own code it starts to make sense. But the authors aimed this book at the java programmer - typically a more technically proficient beast than the tester.
I won’t try and summarise the book contents in this review as you can read the contents online. Really the book tries to cover lots of different ‘typical’ Java testing situations and show ways of using TestNG to test your code. Some of them really interesting - I particularly liked the conciseness of some of the Enterprise testing examples.
For testers - htmlunit and Selenium get cursory mentions and probably won’t help you very much. Check out the Selenium-grid examples which use TestNG for more examples.
A really important book. But not quite what I hoped for. I wanted a more tutorial approach to learning TestNG and its capabilities. I think I could find most of the information I want in here, but I’ll have to read and re-read this book a few times, spread over a few months to really understand the flexibility of TestNG. And I’ll have to look at all the example code and figure out if/how I could use the technique to aid my System testing. So I’ll have to stick with the basics at the moment and hope that the more I use it, the more I’ll understand it - no easy routes into this tool it seems.
This book will probably work really well for the Java programmer and it has lots of really focused examples for common Java testing approaches.
For the tester wanting to use it for your functional testing then you’ll get the basics here and understand grouping but you’ll still have to struggle to learn the optimum ways of using the tool. The enormous flexibility of TestNG still feels just out of reach for me at the moment but the future seems too tempting to stop trying.
- TestNG home page
- TestNG documentation
- GTAC 2007 talk on TestNG by Cedric Beust
- A simple tutorial from JavaLobby
- Cedric Beust’s Blog
- Interview and excerpt on InfoQ
- Sample Chapter from devX - Chapter 3 Enterprise Testing
- ServerSide book review
- TestNG on the Google Toilet
- tutorial from Jorge De Castro
- TestNG tagged on JavaWhat