Does anyone have any tips on how to properly manag...
# test
m
Does anyone have any tips on how to properly manage large data literals in Kotlin tests? I'm writing unit tests for data mapping, so I have to do this: 1. Create test input data 2. Create expected output data 3. Perform mapping 4. Make sure output of the matches matches expected data Problem is that input and/or output data can be big data class with lots of nested data, which means that 95% of the code in the test function is just creating those data classes, creating a big mess. I could move this out of test methods, but every single test method has slightly different data (since it tests different thing), so I cannot have one universal constant with that data class in. I could move the data to resources as some kind of structure (such as JSON), but then I also have to build and maintain deserialization of that data for tests.
d
You could try Approval Tests - check out https://github.com/dmcg/okey-doke
m
From what I understand this library only changes how asserts work, not how data is created?
d
Basically you don’t create a representation of the desired result, you write the actual to disk and approve it if it is ok