在VS2010中调试代码时,集成测试是否异步(使用C#代码)?
关于集成测试,我遇到了以下问题 代码(使用一些其他函数很简单)。我已经在在VS2010中调试代码时,集成测试是否异步(使用C#代码)?,c#,asp.net-mvc-3,testing,integration-testing,C#,Asp.net Mvc 3,Testing,Integration Testing,关于集成测试,我遇到了以下问题 代码(使用一些其他函数很简单)。我已经在AddItem函数上设置了断点 [TestInitialize] public void MyTestInitialize() { Assert.IsTrue( AddItem() ); } [TestCleanup] public void MyTestCleanup() { Assert.IsTrue( RemoveItem() );
AddItem
函数上设置了断点
[TestInitialize]
public void MyTestInitialize() {
Assert.IsTrue( AddItem() );
}
[TestCleanup]
public void MyTestCleanup() {
Assert.IsTrue( RemoveItem() );
}
[TestMethod]
public void ListTest(){
AClass test = new AClass();
Assert.IsTrue(test.List().Count > 0);
}
private bool AddItem() {
AClass obj = new AClass();
Assert.IsTrue(obj.Add("test", "123")); //no duplicate will be allowed ! (return false if duplicate found)
obj.Files = ConstructFiles();
...
...
}
private string[] ConstructFiles(){
return Directory.GetFiles(@"/folder/files", "*.doc");
//when execute the above code then the breakpoint from `AddItem` is reached !!!
}
测试时,ListTest
将自动调用AddItem
(因为TestInitialize
属性)
第一次调用正常,但当此函数(AddItem
)调用另一个函数ConstructFiles
时,将到达AddItem
的断点,并再次执行该函数
[TestInitialize]
public void MyTestInitialize() {
Assert.IsTrue( AddItem() );
}
[TestCleanup]
public void MyTestCleanup() {
Assert.IsTrue( RemoveItem() );
}
[TestMethod]
public void ListTest(){
AClass test = new AClass();
Assert.IsTrue(test.List().Count > 0);
}
private bool AddItem() {
AClass obj = new AClass();
Assert.IsTrue(obj.Add("test", "123")); //no duplicate will be allowed ! (return false if duplicate found)
obj.Files = ConstructFiles();
...
...
}
private string[] ConstructFiles(){
return Directory.GetFiles(@"/folder/files", "*.doc");
//when execute the above code then the breakpoint from `AddItem` is reached !!!
}
为什么?
当然,我还有另一个使用
TestMethod
属性的测试,但是当第一次调用AddItem
时,它调用ConstructFiles
您的obj.Files setter是否调用AddItem?当到达断点时,查看调用堆栈并查看调用的内容。这应该给你一个明确的指示。我已经观察了调用堆栈,在继续测试其他函数时从MyTestInitialize调用它。你是使用MSTest、NUnit还是…?我正在Visual Studio(CTRL+R,a)中运行测试,可能是关于MSTest。。。