0
Class QueryGenerator .. String generateQuery() { final String jsonString = anotherClass1.method(); final Map<String, List<POJO> map = someMethod1(jsonString); final List<POJO> pojos = someMethod2(map); final POJO chosen_pojo = anotherClass2.method(); final String query = ... //do something to generate the query; } .. someMethod1() { //do something}; someMethod2() { //do something}; } 

This class has a json string and retrieves a query string from it. In between, there are a lot of steps, (deserializing, storing to POJO etc), and each step is handled by a different class. All of these classes are called from this method.

For unit test, is it enough to test only the final step to ensure the query generated is correct? (If that step is correct, all steps above it is also correct, right?).

1 Answer 1

1

If your method does so many different things at once, you probably should divide it's responsibilities to different methods or even classes. If your methods become harder to unit-test is because your methods has to much responsibilities. You can see how your methods use so many different data that really could be processed by other classes as well so you should at first refactor your method to make it actually performing only last part.

See, you can easily test someMethod1() and someMethod2() separately so you can rely on them working properly. If your method divide most of it's responsibilities, you can test them separately as well.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.