我有一个编译的DLL,其中包含一个数学算法,该算法使用配置文件进行设置。我有几个集成测试,其中每个测试使用不同的配置文件并运行算法来测试各种计算。问题是如果我运行一个测试,它就会通过。但是如果我在一个播放列表中运行它们,或者只是选择"运行全部"他们失败了。计算的值不正确。似乎配置文件每次都没有被替换,我不知道如何纠正它。所有输入和配置文件都设置为始终复制,并且我已验证它们是否已部署到测试目录中。
样本如下:
[TestClass]
public class MyTestClass
{
[TestMethod]
public void TestFunction1()
{
// before running the test, copy the config for this test and rename it to
// the correct name so the algorithm picks it up
System.IO.File.Copy("DesiredConfigFile.config", "algorithm.config", true);
RunTest();
}
[TestMethod]
public void TestFunction2()
{
// before running the test, copy the config for this test and rename it to
// the correct name so the algorithm picks it up
System.IO.File.Copy("DesiredConfigFile_2.config", "algorithm.config", true);
RunTest();
}
private void RunTest()
{
var myInput = ReadInputFile("MyInputFile.txt");
// when the algorithm object is created, it reads algorithm.config
// to get some constants and whatnot needed for the math
using (var myAlgorithm = new MyAlgorithm())
{
// do some set-up
var results = myAlgorithm.Compute(myInput);
// verify results = fail
}
}
}