I use JUnit and the standard practice of having a XXXTest class for each class I am testing. When writing some tests today I noticed that the test class was about to reach 10000 lines.
Are there some best practices relating to the maximum length of a unit test class? Should I split my unit test class into multiple classes?
Your unit tests should be as verbose as they need to be to reach the level of confidence you need in your code.
I'd say if your test type is that long it is likely because you have a lot of setup/teardown boilerplate, which could indicate you need to abstract some collaborators (e.g. use interfaces and mocking), or introduce some test helper methods to refactor the boilerplate. It might also indicate your type is doing too much, and needs refactoring.
If you refactor the type, you'll likely see the corresponding test type get smaller too.
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