I was thinking about unit tests in my all projects. And I faced interesting question. I always create isolated test class for each class. Test class tests only one class, all external functionallity is mocked. Should I create test class for each class that I want to check? I mean if I have a few classes in the same package, e.g.:
-org.mySample.dictionaries
--DictionaryConverter.java
--DictionaryDaService.java
And DictionaryDaService uses DictionaryConverter for any purposes. It means that I can test DictionaryConverter class through the DictionaryDaService.
I'm pretty sure it's not really good practise because it will be a lot of connections between DictionaryDaServiceTests and DictionaryConverter original class. Another words, I break concept about associations between classes. My test passing depends on two classes the same time.
But the point is that in the company project I often faces same unit tests. Just wanted to get some points of view and more expierence about other developers approaches in that case.
What would you do? Do you create each test class for each class? Or there is no precisely right concept how to write tests?
unit
? I like the answer of Roy Osherove in The Art of Unit Testing: A unit is all the code that has the same reason to change. – Timothy Truckle Jan 11 '18 at 10:32