I have a method that has some data objects passed into it, does some calculations to populate previously empty fields on the objects based on the other fields and then sends back the results. This method does not really cross integration boundaries – the data objects are entities with a fairly complex tree of dependencies on other entities, but from this method’s perspective they are just objects with state (thank you ORM).
It seems to me that unit testing this would require a check of state – set up some data, run the code to do the calculations and check the results. Is this a legitimate case for ignoring what seems to be across the board advice that tests should check behaviour, not state? Or am I misreading the test-driven literature somewhat?
I’d say you’re testing the behaviour of the method which does the calculations, so it’s not a problem.
Some people might suggest that having the behaviour in a separate method (as a service) and not on the classes which hold the data could be a code smell, but that’s a different issue.