加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

如何对C进行单元测试(借助代码块)?

发布时间:2020-12-16 06:58:10 所属栏目:百科 来源:网络整理
导读:我有一个单元测试C项目的功课任务. 它是用代码块编写的. 以下是代码中的一个示例: void ServerUserWrite(int Command) //Command "1" prints an extra row into server. For example addinga new user. it expects that the extra row with the correct dat
我有一个单元测试C项目的功课任务.
它是用代码块编写的.
以下是代码中的一个示例:

void ServerUserWrite(int Command)  //Command "1" prints an extra row into server. For example addinga new user. it expects that the extra row with the correct data is already existing in the structure.
{
        FILE *UserDataBase;
        int i,j;
        UserDataBase=fopen(UserDatabasePath,"w");
        if(Command==1)
        {ServerUserCount=ServerUserCount+1;}
        fprintf(UserDataBase,"%dn",ServerUserCount);
        if(ServerUserCount>0)
        {
                for(i=0;i<ServerUserCount;i++)
                {
                        fprintf(UserDataBase,"%d ",UserDB[i].UserID);
                        fprintf(UserDataBase,"%s ",UserDB[i].User);
                        fprintf(UserDataBase,UserDB[i].UserPasswordLength);
                        fprintf(UserDataBase,UserDB[i].Encrypter);
                        for (j=0;j<UserDB[i].UserPasswordLength;j++)
                        {fprintf(UserDataBase,UserDB[i].Pass[j]);}
                        fprintf(UserDataBase,UserDB[i].BackgroundColor);
                        fprintf(UserDataBase,UserDB[i].ForegroundColor);
                        fprintf(UserDataBase,UserDB[i].UnreadMessages);
                        fprintf(UserDataBase,UserDB[i].UnreadTweets);
                }
        }
        fclose(UserDataBase);
}

那么问题是:
是否有任何单元测试框架与代码块结合?
怎么做?

解决方法

不了解代码块,但您可能想使用check.h并遵循本教程:
http://check.sourceforge.net/doc/check_html/check_3.html.
用它编写测试套件非常简单.我了解了它看gstreamer编辑服务,你可能想看看他们的测试套件:
http://cgit.freedesktop.org/gstreamer/gst-editing-services/tree/tests/check/ges 他们重新实现了它,但它的工作方式基本相同.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读