与 MSTest 共享单元测试
我有大约 5-6 份报告,它们的结构相同,使用 Watin,我正在测试这些报告中的每一份。
我有一个共享测试,我称之为“ReportBaseTests”..
public class ReportBaseTests { public string MenuName { get; set; } public ReportBaseTests(string name) { this.MenuName = name; } [TestMethod] public void Perform_Invalid_Date_Range() { } }
但在每个测试中,我都有...
[TestClass] public class Report1Tests : ReportBaseTests { public Report1Tests() : base("Report 1") { } }
这有效...每个报告将有一个单独的 Perform_Invalid_date_range,并且它将转到不同的页面...我希望有人有更好的方法来做到这一点,因为它还为共享测试生成一个单独的“不可运行”测试,因为我没有包含 [TestClass]
现在,我知道我可以使用 NUnit 并传递参数,然而,我暂时坚持使用 MSTest
I have approximately 5-6 reports, they are structured the same, using Watin, I'm testing each one of these reports.
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") { } }
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]
Now, I know I could use NUnit and pass in arguments, however, I'm sticking with MSTest for the time being
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您愿意,可以将 TestContext 支持 添加到您的测试中,并获得ReportBaseTests.Perform_Invalid_Date_Range() 解析 TestContext.FullyQualifiedTestClassName。对于一个简单的测试,我认为这已经过时了。
对于您的解决方案:只需将
[TestClass]
属性放在ReportBaseTests
上,然后将ReportBaseTests
标记为abstract
。 “不可运行”的测试将消失。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.
For your solution: just put the
[TestClass]
attribute onReportBaseTests
and then markReportBaseTests
asabstract
. The "non-runnable" tests will disappear.