A project is composed of many modules. When we finish a module each time, we should try again to check whether the function is
The execution is correct. Then write the next module. Do not wait until all the modules are written and try again.
Difficult to locate (except for experts ).
Therefore, as a project engineer, writing a token trial is a major skill.
So how do I write a trial example of a notebook?
In fact, we use our own modules to check whether the execution results are consistent with the expected results.
For example, if you have written an add function and want to test it, we will write a test_add function.
# Include <stdio. h> int add (int A, int B) {return a + B;} int test_add (void) {int ret = 0; ret = add (1,1); If (Ret! = 2) {return 1;} ret = add (2, 2); If (Ret! = 4) {return 2;} ret = add (3, 3); If (Ret! = 6) {return 3;} return 0;} int main () {int ret = 0; ret = test_add (); If (Ret! = 0) {// here, based on the returned value, determine which sequence is incorrect. Printf ("test failed, ret = % d \ n", RET);} else {printf ("test OK! ");}}
Of course, we can also use some open-source trial code. Below are two simple language unit trial frameworks.
For example, cutest, a simple C unit worker test see the link http://pan.baidu.com/s/1hqeg7qO
Cunit: It is provided to users in the form of a static library. Users can directly connect to this static library when coding. It provides a simple unit testing framework and supports a wide range of asserted statements for frequently used data types. See link http://pan.baidu.com/s/1gd9WCgV