JUnit test spirit

Suppose you have the following logic:

processMissing(masterKey, masterValue, p.getPropertiesData().get(i).getDuplicates());

public StringBuffer processMissing(String keyA, String valueA, Set<String> dupes) {
// do some magic
}

I would like to write a jUnit test for processMissing, testing its behavior when events match is null.

What am I doing here? Do I have to check how methods with null or possibly method method calls are handled to make sure that null is never sent?

Generally speaking, what is the approach here? We cannot check everything for everything. We also cannot handle all possible cases.

What should you think when deciding which tests to write?

I thought of it like this:

  • I have a specific expectation using the method
  • The test should confirm that my wait and confirmation method work in this state.

Is this the right way to think about this?

Thank you and please let me know

+3
2

, null .

, , .

, :

  • .
  • ( , ).
  • , , null .
  • unit test, , .

FindBugs , @NonNull, .

, Java-, NULL .

+1

, API , , , JSR 305 , . , javadoc.

, , , , , IllegalArguemntException, NullPointerException , , , - . JUnit docs.

0

Source: https://habr.com/ru/post/1763123/


All Articles