Data driven integration test tools for java
I'm facing what I would think is a common problem, but I haven't found much discussion or existing tools to address it. I am trying to set up an integration test system (already having a strong suite of unit tests) which supports QA submitting input data and expected results (in the form of flat files, ideally) which can be run from a standardized junit class.
I have a plan to roll my own here using the junit @Paramaterized
annotation. I'm imagining each set of data and results having a control file, and all control files being placed in one directory. The parameter generator method would scan this directory and return a list of these files. The test constructor would then read this file and set up the input data and expected results.
Before I start writing this, I wanted to see if there already existed tools to do this type of thing, and if not, get some opinions on the solution I am proposing.
The application itself is a purely back end ETL type tool, which takes data from several input files in various formats and produces results in a database. I already have some static integration tests which use a Derby in memory database to check the results for trivial input data, and I plan to use a similar system to confirm the data here. Expected results would be in the form of (key_value, column, expected value)
triples. I want to use junit in order to开发者_StackOverflow tie into the rest of our testing and result reporting infrastructure.
Have a look at Spock, a Groovy-based testing framework with strong support for data-driven testing. Spock is designed for testing Java (and Groovy) code, and is fully compatible with JUnit (in fact, Spock tests are run with JUnit). See here for a simple example test that pulls data from a database.
In general, your plan sounds reasonable to me, and can also be realized with plain JUnit and @Parameterized. Spock and Groovy can make your life easier though. For example, working with text files and databases is much easier in Groovy than in Java.
Disclaimer: I'm the creator of Spock.
I prefer Spock myself. But I do see that there is a JUnitParams framework out there that is much more readable than straight JUnit parameterized tests:
https://github.com/Pragmatists/junitparams
A great description can be found at:
https://weblogs.java.net/blog/johnsmart/archive/2014/07/23/data-driven-unit-testing-java
For others hitting this question....
精彩评论