Why does unitest have to use a class? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why does unitest have to use a class?

I'm learning how to use unitest.But I'm wondering why can't I use a simple function or AssertEqual statement. Why did they make it to need classes?

13th Oct 2021, 11:59 AM
Richard
Richard - avatar
1 Answer
+ 1
For convention, Unit test must be in a separate project. Tests try to prove or verify that our code behaves correctly. Generally a unit, is the source code that we want to test, and we want to test [Small Units] of code. We could test the code within a single method that calculates an average for example, and that method will be the unit, even if the method is part of a larger abstraction like a class. Finally, the unit test is automated, meaning that every time we write a test, we can run that test effortlessly in the future using a tool known as a Test runner. A test runner finds all the unit tests you've written, runs each test, and provides you with a report to tell you if the test has passed or if something has failed. If you wanna know more, just search on google. There are tutorial and course on youtube to. I followed one course on Plural. Unfortunately, in real life on real business projects, you don't have always time to make them.
13th Oct 2021, 1:25 PM
Sudo-Ale
Sudo-Ale - avatar