当前位置:网站首页>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
边栏推荐
- LeetCode力扣题目总结(题目编号:53、3、141、面试题022、剑指offer链表中环的入口节点、20、19、牛客NC1、103、1143、牛客127)
- Basic shell operations (Part 1)
- Excellent Allegro skill recommendation
- Clickhouse learning (III) table engine
- Sudoku (DFS)
- Flask reports an error runtimeerror: the session is unavailable because no secret key was set
- ML.NET相关资源整理
- Component transfer participation lifecycle
- How to quickly experience oneos
- 解决Base64 报错 Illegal base64 character
猜你喜欢

Importerror: no module named XX

Excellent Allegro skill recommendation

SAP sm30 brings out description or custom logical relationship

Node: file write data (readfile, WriteFile), two modes: overwrite and increment

数学建模——微分方程

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

WQS binary learning notes

C language sorts n integers with pointers pointing to pointers

(视频+图文)机器学习入门系列-第2章 线性回归

Osg3.6.5 failed to compile freetype
随机推荐
Node: file write data (readfile, WriteFile), two modes: overwrite and increment
C language calculates the length of string
Chrony time synchronization
The computer video pauses and resumes, and the sound suddenly becomes louder
ML.NET相关资源整理
Solve the problem of false Base64 character in Base64
2022年P气瓶充装考试模拟100题模拟考试平台操作
Clickhouse learning (II) Clickhouse stand-alone installation
Sword finger offer 26. substructure of tree
Basic crawler actual combat case: obtaining game product data
Back up Google or other browser plug-ins
01 knapsack about from two-dimensional optimization to one-dimensional optimization
Thrift installation manual
LeetCode力扣题目总结(题目编号:53、3、141、面试题022、剑指offer链表中环的入口节点、20、19、牛客NC1、103、1143、牛客127)
SAP sm30 brings out description or custom logical relationship
Group Backpack
Eggjs create application knowledge points
Crawling JS encrypted data of playwright actual combat case
Use SQL client How can the job generated by SH achieve breakpoint continuation after cancle?
谷歌浏览器免跨域配置