我正在开发一个软件开发项目,该项目使用主要用C和C#编写的代码.目前,测试的责任主要落在开发人员更改代码上.
我有兴趣实现自动化测试框架,以帮助我们提高代码质量.特别是,每次将代码提交到版本控制时都会运行自动化测试.
我对自动化测试(或单元测试)的经验不多.有没有人使用C/C#的测试框架进行开发,如果是这样,我们在整个公司范围内以及相当大的现有代码库上实现它可能会遇到什么障碍?
特别是,我一直在研究如何使用Gallio.对此特定产品的任何评论将不胜感激.
附加信息:
将单元测试添加到现有项目
单元测试旧版ASP.NET Webforms应用程序
将现有代码移动到测试驱动开发
收藏.NET单元测试框架
我正在使用 FxCop 1.36 运行静态代码分析,并且不断收到警告 CA1034:NestedTypesShouldNotBeVisible。
我会理解父类是否被声明为内部或私有,但它是公共的。为什么将 TimerReset 声明为公开是不好的?
我错过了什么,或者这是可以忽略的东西?
感谢您提供任何意见!
以下是导致此警告的代码摘录:
namespace Company.App.Thing
{
public partial class Page : XtraPage
{
public delegate void TimerResetDelegate(object sender, EventArgs e);
private TimerResetDelegate _timerReset;
public Page()
{
InitializeComponent();
}
public TimerResetDelegate TimerReset
{
set
{
if (null != (_timerReset = value))
{
checkBox.Click += new EventHandler(_timerReset);
textField.Click += new EventHandler(_timerReset);
textField.KeyDown += new KeyEventHandler(_timerReset);
TimeField.Click += new EventHandler(_timerReset);
TimeField.KeyDown += new KeyEventHandler(_timerReset);
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud) 我需要在ANSI C中以"blah.bleh.bloh"格式的字符串中提取信息.通常我会使用strok()来完成此操作,但是因为我通过strtok获取此字符串,并且strtok不是线程安全的,我不能使用这个选项.
我编写了一个手动解析字符串的函数.这是一个snippit:
for(charIndex=0; charIndex < (char)strlen(theString); charIndex++)
{
if(theString[charIndex] == '.')
{
theString[charIndex] = '\0';
osi_string_copy_n(Info[currentInfoIndex], 1024, theString, charIndex + 1 );
currentInfoIndex++;
theString = &theString[charIndex + 1];
}
charIndex++;
}
Run Code Online (Sandbox Code Playgroud)
如你所见,我试图找到第一次出现'.' 并记下角色的索引.然后我转换'.' 到一个null char并将第一个字符串复制到一个数组.
然后我想将指针更改为刚刚找到分隔符后的开始,基本上给了我一个新的更短的字符串.
不幸的是我收到错误:
theString = &theString[charIndex + 1];
Run Code Online (Sandbox Code Playgroud)
错误是:
error C2106: '=' : left operand must be l-value
Run Code Online (Sandbox Code Playgroud)
为什么我不允许像这样移动指针?我的方法有缺陷吗?也许有人有更好的想法来解析这个字符串.
编辑:在回应评论时,theString的声明是:
char theString[1024] = {0};
Run Code Online (Sandbox Code Playgroud)
此外,我保证theString永远不会超过1024个字符.
在另一个问题中,接受的答案显示了一种将文件内容读入内存的方法.
我一直在尝试使用此方法读取文本文件的内容,然后将其复制到新文件.但是,当我将缓冲区的内容写入新文件时,文件末尾总会有一些额外的垃圾.这是我的代码示例:
inputFile = fopen("D:\\input.txt", "r");
outputFile = fopen("D:\\output.txt", "w");
if(inputFile)
{
//Get size of inputFile
fseek(inputFile, 0, SEEK_END);
inputFileLength = ftell(inputFile);
fseek(inputFile, 0, SEEK_SET);
//Allocate memory for inputBuffer
inputBuffer = malloc(inputFileLength);
if(inputBuffer)
{
fread (inputBuffer, 1, inputFileLength, inputFile);
}
fclose(inputFile);
if(inputBuffer)
{
fprintf(outputFile, "%s", inputBuffer);
}
//Cleanup
free(inputBuffer);
fclose(outputFile);
}
Run Code Online (Sandbox Code Playgroud)
输出文件始终包含输入文件的精确副本,但随后在末尾附加了文本"MPUTERNAM2".任何人都可以解释为什么会发生这种情况?
我在一些代码中遇到了这一行,无法在任何地方找到定义的语法:
*(float *)csCoord.nX = lImportHeight* .04f; /* magic number to scale font size */
Run Code Online (Sandbox Code Playgroud)
如果我删除了 f from, .04f 则编译器会发出警告,指出由于从'double'转换为'float'而导致数据丢失.我假设 f 正在进行某种类型转换.
谁看过这个吗?这在C标准中定义在哪里?