Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suggestion for JUnit testing

All,

While writing a test method for method A (which has many internal conditions), should I focus on testing a single condition each time? I am finding it difficult to structure a test method for method A that would cover all the code path in method A.

Can anyone please suggest me how to go about writing a test method.?

like image 274
name_masked Avatar asked Dec 01 '25 17:12

name_masked


1 Answers

Do not feel the need to have one-test-per-method. Keep your unit tests fine-grained, descriptive, and easy to understand. If that means multiple, similar tests all calling the same target method, then do it.

For that matter, try and avoid the habit of systematically writing a unit test for each method. Unit testing should be well thought-out, not habitual. They should describe the behaviour of classes, rather than of individual methods.

like image 119
skaffman Avatar answered Dec 06 '25 01:12

skaffman