Development is one of the key activities that build, enable and ultimately power the overall mobile environment. Today we are sharing some key insight into an important aspect of development – testing framework – from one of our most experienced developers here at Smaato.
Developers know that choosing the right testing framework for the job can be really complicated. The jUnit Framework is an excellent Java testing tool, but for specific tests that require sample data, better tools - like the Groovy-based Spock - are available. This post describes how to use Spock and how it handles test data. It also explores how Spock tests can be executed with jUnit tests and maven.
How jUnit runs parameterized tests
To have a test that works with a set of test data, you need to define a data method which returns all samples in a Collection. Each sample is used to instantiate a new test class. The constructor needs suitable parameters for the test samples. Then all test methods are executed, as you can see in the code samples below: