How much does one TestCase cost?

I still have not written a proper test, only the small programs that I would choose after the test were successful. I was looking at the Python unittest module and tutorials all over the internet, but something is unclear to me.

How much does one TestCase cost? I saw examples on the Internet that have TestCase classes with only one method, as well as classes that test almost all of the available functions.

In my case, I am trying to write a test for a simple flowering filter. Do you think I should organize my test cases?

+4
source share
2 answers

Simply put: one unit test should cover a separate function of your program. That is all that can be said. That's why they are called unit tests.

Of course, what we understand by attribute may differ. Think about the smallest parts of your program that might break or not work properly. Think about the business requirements of your code. These are the parts that you want each of them to be covered with a dedicated unit test.

Unit tests are usually small, isolated, and atomic. They must be understandable , they must refuse / pass independently of each other , and perform quickly . A pretty good indication of the right unit tests is one statement - if you find that you are writing more, you are probably testing too much, and this is a sign that you need more than one test for this function. However, this is not a strict rule - the more complex the code, the more complex unit tests.

When writing tests, it’s easy to break down the functionality of the code and check those individual parts (this should give you an idea of ​​the atomicity of your tests). For example, if you have a method that checks the input, it calls the service and finally returns the result, you usually want all three (check, call, return) to be covered.

+5
source

I would create one TestCase with several test methods. The flowering filter has simple semantics, so there is only one TestCase. I usually add TestCase for each function.

+1
source

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


All Articles