0

I have a test class with about 25 tests that are testing the different aspect of it.

I wonder

  • Should I break it down into smaller classes?
  • If so, then what is the best naming/packaging convention?

lets say my class name is abcService and I want to break it down into x, y and z aspect of it.

  1. name test classes as xTest, yTest and zTest. the problem with this way is, it might be hard for someone else to find tests for the abcService class as it have different name and usually people look for abcServiceTest file.
  2. create folder in test section and name it abcServiceTest and move xTest, yTest and zTest into it.
  3. name test classes as abcServiceTestForX , abcServiceTestForY and abcServiceTestForZ
0

The unit test file has a direct correlation to the code file it is testing. So, the underlying problem is most likely with code itself. If you refactor the code that is under test into smaller classes with single responsibilities, then the unit test file(s) will be smaller as well and then will be no need to create multiple test file with some sort of naming schema/convention.

25 tests is not that bad. If many tests are just variations on a theme, consider creating one test that is data driven from a list of data in the test itself or external in a file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.