I have a basic unit test (for the sample) that involves this code: void testShouldCreateACar() {  Car car = someone.createFerrari();  assertTrue(car.name == Ferrari); // can't access name since name is private}I can't access name since there's not a getter in Car (or Ferrari) class for it.I don't want to create getters only for unit testing purpose. Note that the SUT is out of the Car's package (distinct package).Note also that the Ferrari's constructor is private (creation only accessible through createFerrari() method on someone.What is a good practice to achieve this assertion? 
Unit testing / How to validate private fields of a newly created object?
java;object oriented;architecture;unit testing
If it is the case that the name of the car isn't publicly available in any way at all, then it makes no sense to test it, because obviously it doesn't matter to any client code. If the name of the car matters, even if you can't actually see it by inspecting the field, then exercise some method that relies on the name being correct and assert against some visible result from that.Edit following clarifying comment:If your ORM cares about private fields, I'd say this would be much more beneficial to test indirectly via integration tests. I probably wouldn't go as far as writing specific tests for all fields of all classes though, seems too granular for me. I'd recommend just writing some integration tests that require persistance to work at all, and you'll get the reflection checked implicitly.