Can you test an apex class using more than 1 Test class where the combined testing of the 2 (for example) test classes means the target class is tested to more than 75%/
1 Answer
You can certainly do that, you can have as many test classes as you want. In fact I encourage you to create test classes that for example have 5 test methods that test a specific functionality of the code, instead of having a huge class with 30 test methods.
That way you know where to go to solve your problem, you have more control on the data you create when testing, for example using the @testSetup annotation on test setup private method, and in general it's more compact and flexible.
Also make sure that you follow a naming convention for your unit tests, I like Roy Osherove's naming convention but you can google other conventions and see what you like and stick with it.
-
Thanks Mihai, but will the test coverage be cumulative when deploying to Production if the 30 test methods are spread over 5 classes for example? So each test class covers say 15% of the class (on average), does the combined coverage then add up to 75%? Apr 5, 2016 at 8:59
-
Yes it will, it doesn't matter where your test methods are, the only thing it matters is that you have meaningful unit tests that run your code. Apr 5, 2016 at 9:04
-
1Just to clarify: if all 5 classes are covering the same 15% (ie: they call the same methods), then they will not add up– mkormanApr 5, 2016 at 9:41