共享单元测试的MSTest [英] Shared Unit Tests with MSTest
问题描述
我有大约5-6次报告,它们的结构相同,采用华廷,我测试的这些报告每一个。
I have approximately 5-6 reports, they are structured the same, using Watin, I'm testing each one of these reports.
我有一个共享的测试,我称之为ReportBaseTests..
I have a shared test, I call "ReportBaseTests"..
public class ReportBaseTests
{
public string MenuName { get; set; }
public ReportBaseTests(string name)
{ this.MenuName = name; }
[TestMethod]
public void Perform_Invalid_Date_Range()
{
}
}
但在每一个测试中,我有...
but in each of my tests, I have...
[TestClass]
public class Report1Tests : ReportBaseTests
{
public Report1Tests()
: base("Report 1")
{ }
}
本作品...每个报告都会有一个单独的Perform_Invalid_date_range,它会转到不同的网页...我希望有人有一个更好的方式来做到这一点,因为它也产生一个单独的非可运行用于测试的共享的测试,因为我没有包括[TestClass中]
This works... each report will have a seperate Perform_Invalid_date_range, and it'll goto a different page... I was hoping someone had a better way to do this, as it also produces a seperate "non-runnable" test for the shared test since I didn't include the [TestClass]
现在,我知道我可以把NUnit和传递参数,但是,我与MSTest的坚持暂时
Now, I know I could use NUnit and pass in arguments, however, I'm sticking with MSTest for the time being
推荐答案
如果你愿意,你可以添加的的TestContext支持您的测试,并有ReportBaseTests.Perform_Invalid_Date_Range()解析<一个href=\"http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.testcontext.fullyqualifiedtestclassname.aspx\"相对=nofollow> TestContext.FullyQualifiedTestClassName 。对于一个简单的测试,我认为这是超必杀。
If you wanted, you could add TestContext support to your tests and have the ReportBaseTests.Perform_Invalid_Date_Range() parse the TestContext.FullyQualifiedTestClassName. For a simple test I think that's over kill.
有关您的解决方案:只是把 ReportBaseTests
的 [TestClass中]
属性,然后标记 ReportBaseTests
为摘要
。 非可运行测试将消失。
For your solution: just put the [TestClass]
attribute on ReportBaseTests
and then mark ReportBaseTests
as abstract
. The "non-runnable" tests will disappear.
这篇关于共享单元测试的MSTest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!