Let's say you make an application that attempts to transliterate stuff from alphabet A into alphabet B, as closely as possible.
Because language B is very complex, this is not always successful. But you do get an approximate transliteration.
How would you build unit tests in this case, considering that you expect 20-30% to fail?
At each check-in, all tests should pass. You'll see tests fail initially when you do TDD, and that's the reason you can trust them. As part of the TDD red/green/refactor cycle, though, at the end of each iteration, you should be left with an all green test run.
One of the benefits of unit tests is that they isolate a function, class or method and only test that piece of code. Higher quality individual components create overall system resiliency. Thus, the result is reliable code. Unit tests also change the nature of the debugging process.
A good unit test encompasses many different attributes or practices, including that it should: Be small and isolated. Be about something highly specific regarding the code. Have a ratio of testing to assertion near 1, thereby making it easier to identify any failed assertion.
Unit testing guidelines demand that a good unit test should be independent, repeatable, readable, exhaustive, realistic, maintainable, fast and easy. These are the best practices you want to keep in mind in order to write effective unit tests and make sure the time invested is truly useful.
It must always be the goal that your unit test is successful. The way you use it, you can not differentiate between serious errors in your software and the errors in the translations you seem to expect.
I would suggest to separate both:
Unit test should be deterministic. Failing test should indicate software failure, not something that "works as intended". For your case, prepare data in a way you can be sure of results and test for them, whether conversion succeeds or fails (testing for failure is always an option, given you expect failure - important is that you're always in control of when your test passes/fails).
A unit test that is expected to fail is not a unit test. You need to change the definition of success by using an evaluation function that acts as a filter and decides if it is "close enough" and determines pass/fail. As your translator gets better, you can raise the bar in the filter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With