S
S
s2019-07-19 18:26:40
Java
s, 2019-07-19 18:26:40

What should be unit testing cases?

I recently started doing unit testing and wondered what cases I need to test the code for.
I singled out for myself: for checking calls to locked methods, for checking for null and for expected errors in various cases. What cases could I have missed and do I understand unit testing correctly in principle?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
BorLaze, 2019-07-21
@solovladys

Basically, you are correct.
Unit tests are designed to provide two types of checks - results checks and behavior checks.
For example, we are testing a method for sorting an array of strings.
The first check is obvious: The
second case is more difficult:

sort(null)
sort({})
sort({"a"})
sort({"c", null "b"})
sort({"c", "", "b"})
sort({"b", "a", "b"})

More difficult, because at this stage you need to figure out which set of input data may be critical (depending on the algorithm used) and provide the necessary checks that the method under test behaves correctly.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question