Suppose I want to write a test for a Java class that provides a method for reading and analyzing external files (more precisely, the files will be JSON, and I will use Jackson).
In addition, I have some examples of JSON files that I have analyzed, and I also have a vague idea of ββwhich Java object this SomeMagicalReader.readPony("path/to/location/pony.json") method SomeMagicalReader.readPony("path/to/location/pony.json") should return; if I manage to get readPony to return some kind of PonyObject , I think there is an idea how to verify that the produced PonyObject is what I expect.
The question I have is to provide readPony function readPony test data. I probably think too much about this, but (1) is there an idiomatic way of "Java + Junit"? (= testing a method that reads external files?). Copy the contents of an example file as a String variable in test code? (They are quite short, but it will still look pretty ugly.) Put an example of JSONs ... somewhere and call readPony using the path? (This sounds more reasonable.) (2) What would then be a canonical place to host such external JSON test files if my tests are organized in a hierarchy of Maven-style test packages, for example. src/test/java/com/stuff/app/package/SomeMagicalReaderTest.java ?
java json maven file-io junit
kekkonen
source share