我有一個單元測試C項目作業的任務。 它是用代碼塊編寫的。 這裏有一個例子從代碼:如何單元測試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,"%d\n",ServerUserCount);
if(ServerUserCount>0)
{
for(i=0;i<ServerUserCount;i++)
{
fprintf(UserDataBase,"%d ",UserDB[i].UserID);
fprintf(UserDataBase,"%s ",UserDB[i].User);
fprintf(UserDataBase,"%d ",UserDB[i].UserPasswordLength);
fprintf(UserDataBase,"%d ",UserDB[i].Encrypter);
for (j=0;j<UserDB[i].UserPasswordLength;j++)
{fprintf(UserDataBase,"%d ",UserDB[i].Pass[j]);}
fprintf(UserDataBase,"%d ",UserDB[i].BackgroundColor);
fprintf(UserDataBase,"%d ",UserDB[i].ForegroundColor);
fprintf(UserDataBase,"%d ",UserDB[i].UnreadMessages);
fprintf(UserDataBase,"%d\n",UserDB[i].UnreadTweets);
}
}
fclose(UserDataBase);
}
那麼問題是: 有沒有單元測試框架與代碼塊相結合? 以及如何做到這一點?