I am currently working on a module that takes one of our business objects and returns a json representation of this object to the caller. Due to limitations in our environment, I cannot use any existing json writer, so I wrote my own, which is then used by the author of the business object to serialize my objects. By json tested similarly to this
@Test public void writeEmptyArrayTest() { String expected = "[ ]"; writer.array().endArray(); assertEquals(expected, writer.toString()); }
which is controlled only by the small output generated by each instruction, although I feel that there should be a better way.
The problem I'm currently facing is writing tests for the object writer module, where the result is much larger and much less manageable. The risk of spelling errors in the expected lines dropping my tests seems too great, and writing code in this way seems silly and unmanageable in the long run. I constantly feel that I want to write tests to make sure my tests are behaving correctly, and this feeling bothers me.
Which is better for this?
json unit-testing
Mia clarke
source share