当前位置:网站首页>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
边栏推荐
- Basic shell operations (Part 1)
- Component transfer participation lifecycle
- Back up Google or other browser plug-ins
- Use disco diffusion to generate AI artwork in moment pool cloud
- Centos7/8 command line installation Oracle11g
- Cluster usage specification
- The computer video pauses and resumes, and the sound suddenly becomes louder
- Day13: file upload vulnerability
- Hc-sr04 use method and routine of ultrasonic ranging module (STM32)
- 2022 question bank and answers of operation certificate examination for main principals of hazardous chemical business units
猜你喜欢
Crawling JS encrypted data of playwright actual combat case
C language calculates the length of string
谷歌浏览器免跨域配置
Application of matrix transpose
2022年R2移动式压力容器充装考题模拟考试平台操作
英语高频后缀
SAP sm30 brings out description or custom logical relationship
RPC and rest
Google browser cross domain configuration free
【Transformer】ATS: Adaptive Token Sampling For Efficient Vision Transformers
随机推荐
信息系统项目管理师必背核心考点(五十三)质量等级
Analysis of zorder sampling partition process in Hudi - "deepnova developer community"
Play Parkour with threejs Technology
英语高频后缀
AES bidirectional encryption and decryption tool
6.3 references
2022 spsspro certification cup mathematical modeling problem B phase II scheme and post game summary
RPC和REST
MFC integration QT verification and problem handling
RESTful 风格详解
2022 electrician (elementary) test question simulation test platform operation
解决Base64 报错 Illegal base64 character
正则表达式校验版本号
PostgreSQL manually creates hikaridatasource to solve the error cannot commit when autocommit is enabled
Vs2019 compilation cryengine failure problem handling
SAP sm30 brings out description or custom logical relationship
Clickhouse learning (II) Clickhouse stand-alone installation
Is the sub database and sub table really suitable for your system? Talk about how to select sub databases, sub tables and newsql
[opencv] - Operator (Sobel, canny, Laplacian) learning
2022 question bank and answers of operation certificate examination for main principals of hazardous chemical business units