Should I write unit tests when the json schema is validated by a 3rd party library
irl last edited by
I have some json data and I would like to validate the data against a defined json schema. I'm using the ajv library for the validation. On the json schema, there are constraint you can specify like required properties.
Should I still create unit tests with invalid schema and expect it to be invalid or should I just rely on the fact that the library is already well tested and should tell me all the validation errors?
Currently I'm writing unit tests for all constraint to make sure that it will tell me it is invalid, but it is lots of unit tests to maintain.
jeanid last edited by
Unit tests, by the book, are meant to exercise the code you write, isolating it from dependencies (SO calls, external libraries and even language built-in libraries if important for your code) through mocking.
What you may need is integration tests, which means checks that will evaluate if two components can communicate. They are different than integrated tests, which bundles two or more components and evaluate the output of them as a unit.
In integration tests, you rely on the unit tests of the components and exercise the communication:
Does service A send the data firstName and service B reads the data firstName, rather than FirstName or name?
If you don't have such conviction on the unit test quality of the library or if you believe that the authors of the library will not respond to bugs in a timely manner for your project, you should surely do a small amount of integrated testing, by building your app without mocking the library and inputting some special data you want to be more sure.