What are the common tools for unit testing?

Unit testing (module testing) is a small piece of code written by the developer to verify that a small, well-defined function of the code under test is correct. In general, a unit test is used to determine the behavior of a particular function under a particular condition (or scene). For example, you might put a large value into an ordered list and then confirm that the value appears at the end of the list. Or, you might remove characters that match a pattern from the string and then confirm that the string does not actually contain those characters.

Unit testing is done by the programmer himself, and ultimately the programmer himself. It can be said that it is the responsibility of the programmer to write functional code and to be responsible for writing unit tests for their own code. Unit testing is performed to prove that the code behaves in the same way we expected.

The factory tests each component before assembling a TV set. This is the unit test.

In fact, we are doing unit tests every day. You wrote a function, in addition to the very simple, always have to perform a look to see if the function is normal, sometimes you have to find a way to output some data, such as pop-up information window or something, this is also unit test, put this unit The test is called a temporary unit test.

Software that only performs temporary unit testing, the testing of the code is very incomplete, the code coverage is more than 70% is very difficult, the uncovered code may leave a lot of small errors, these errors will also affect each other, when the BUG is exposed It is difficult to debug when it comes out, greatly improving the cost of later testing and maintenance, and reducing the competitiveness of developers. It can be said that full unit testing is the only way to improve software quality and reduce development costs.

For programmers, if you develop the habit of unit testing your own code, you can not only write high-quality code, but also improve the programming level.

For full unit testing, test code should be written specifically and isolated from the product code. I think the simpler way is to establish a corresponding test project for the product project, establish a corresponding test class for each class, and build a test function for each function (except very simple). Let me first talk about my views on several concepts.

What are the common tools for unit testing?

It is generally believed that in the era of structured programming, the unit referred to in unit testing refers to functions. In today's object-oriented era, the unit referred to in unit testing refers to classes. In my practice, class as a test unit, high complexity, poor operability, so still advocate the function as a unit test unit, but you can use a test class to organize all test functions of a class . Unit testing should not place too much emphasis on object orientation because local code is still structured. The unit test has a large workload, and it is the last word that is simple, practical and efficient.

There is a perception that only testing the interface of the class (public function), not testing other functions, from the object-oriented point of view, does make sense, but the purpose of the test is to find the error and eventually debug, so as long as it is included The function with a higher probability of error is tested, and it has nothing to do with whether the function is private. For C++, you can use a simple method to separate the functions to be tested: simple functions such as data read and write functions are written in the header file (inline function), all functions written in the source file must be performed Testing (except constructors and destructors).

What are the common tools for unit testing?

Test Management Tools: Tools that can help complete test plans, track test run results, and more. Such tools also include tools that aid in requirements, design, coding testing, and defect tracking;

Static analysis tool: Analyze code without executing code. This tool detects certain defects more efficiently and with less overhead than other methods. Such tools can generally measure various indicators of the code, such as McCabe measurement complexity, Logiscope measurement code and specification recombination, and so on;

Coverage Tool: This tool evaluates the extent to which software is executed after a series of tests. This kind of tool is widely used in unit testing, such as PureCoverage, TrueCoverage, Logiscope, etc.

Dynamic Analysis Tools: This tool evaluates the systems that are running. For example, check the memory usage during system operation, whether there is memory out of bounds, memory leaks, etc. Such tools include Purify, BoundChecker, etc.

Test Execution Tools: These tools automate testing and have execution tools at all levels (unit testing, integration testing, system testing). For example, there are functional test automation tools such as Robot, Winrunner, SilkTest, etc. in the system test phase; and performance test tools such as Loadrunner and SilKPerformer.

White box testing tools mainly include:

(1) Memory resource leak check: bouncechecker in Numega, Purify from RaTIonal

(2) Code coverage check: truecoverage in Numega, Purecoverage in RaTIonal, logoiscope from Telelogic, Macabe from Macabe

(3) Code performance check: trueTIme in Numega, Quantify of RaTIonal

(4) Code static metric analysis quality check tools: logiscope and Macabe

Black box testing tools mainly include:

(1) Client functional test: MI company's winrunner, compuware's qarun, Rational's robot

(2) server-side pressure performance test: MI company's winload, compuware's qaload, Rational's SQAload, etc.

(3) Web testing tools: MI's Astra series, rsw's e-testsuite

(4) Test management tools: rational testmanager, compaware qadirector, etc.

(5) defect tracking tool: trackrecord, Testtrack

Unit testing tool:

(1) Test framework: delphidunit

(2) javajunit

(3) c++cppunit

(4) VisualBasicVBUnit

(5) (.NETplatform) NUnit

Zpal Vape

Shenzhen Zpal Technology Co.,Ltd , https://www.zpal-vape.com

Posted on