当前位置:网站首页>Simple unit testing idea
Simple unit testing idea
2022-07-29 08:43:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm the king of the whole stack , I wish every programmer can learn more languages .
A project is composed of many modules , When we finish one module at a time , You should test whether the function It can be executed correctly . Then write a module , Don't wait for all modules to be written before overall testing , It will be very
Difficult to find the problem ( Except for Masters ).
So as a project t , Writing test cases is a major skill . How to write test cases ?
In fact, I use my own module , See whether the implementation result is consistent with the expected result .
For example, the following , Wrote a add function , To test it , Let's 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, the return value is used to determine which test is wrong .
printf("test failed,ret = %d\n",ret);
}
else
{
printf("test ok!");
}
}Of course, you can also use some open source test code , Here are two simple language unit testing frameworks .
example cutest , ordinary c Unit testing See link http://pan.baidu.com/s/1hqeg7qO
CUnit: It is provided to users in the form of static library , When users write code, they can directly link to this static library . It provides a simple unit testing framework , And it provides rich assertion statement support for frequently used data types . See link http://pan.baidu.com/s/1gd9WCgV
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/118601.html Link to the original text :https://javaforall.cn
边栏推荐
- Opencv cvcircle function
- 【Transformer】SegFormer:Simple and Efficient Design for Semantic Segmentation with Transformers
- Arfoundation Getting Started tutorial 7-url dynamically loading image tracking Library
- Back up Google or other browser plug-ins
- Clion+opencv+aruco+cmake configuration
- C language macro define command exercise
- Data is the main body of future world development, and data security should be raised to the national strategic level
- Importerror: no module named XX
- 完全背包问题 从朴素到终极
- Arfoundation starts from scratch 5-ar image tracking
猜你喜欢

Fastjson's tojsonstring() source code analysis for special processing of time classes - "deepnova developer community"

Deep learning (2): image and character recognition

2022 electrician (elementary) test question simulation test platform operation

【OpenCV】-算子(Sobel、Canny、Laplacian)学习

What if official account does not support markdown format file preparation?

Intel will gradually end the optane storage business and will not develop new products in the future

【Transformer】ATS: Adaptive Token Sampling For Efficient Vision Transformers

C language function output I love you
![A little knowledge [synchronized]](/img/4d/4a8beee749328b5867b59740fd7e78.png)
A little knowledge [synchronized]

Day5: PHP simple syntax and usage
随机推荐
Restful style details
Source code compilation pytorch pit
谷歌浏览器免跨域配置
Importerror: no module named XX
Brief introduction and use of commonjs import and export and ES6 modules import and export
Amazfit dial toolbox Online
To create a thread pool for the rate, start the core thread
Transaction management in SQL Server
完全背包问题 从朴素到终极
Third week weekly report resnet+resnext
Lesson 3 threejs panoramic preview room case
Sword finger offer 27. image of binary tree
Chrony 时间同步
Sword finger offer 50. the first character that appears only once
RPC and rest
状态压缩dp
2022电工(初级)考题模拟考试平台操作
Clickhouse learning (I) Clickhouse?
[[first blog]p controller implementation instructions in UDA course]
用户身份标识与账号体系实践