NUnit,针对多种文化进行测试
我希望使用 NUnit 针对多种文化运行某个项目中的所有测试。
该项目处理应该是文化中立的解析数据,为了确保这一点,我想针对多种文化运行每个测试。
我当前的解决方案是
public abstract class FooTests {
/* tests go here */
}
[TestFixture, SetCulture ("en-GB")] public class FooTestsEN : FooTests {}
[TestFixture, SetCulture ("pl-PL")] public class FooTestsPL : FooTests {}
理想的,我不必创建这些类,而是使用类似的东西:
[assembly: SetCulture ("en-GB")]
[assembly: SetCulture ("pl-PL")]
Using NUnit I wish to run all the tests in a certain project against multiple cultures.
The project deals with parsing data that should be culture neutral, to ensure this I would like to run every test against multiple cultures.
The current solution I have is
public abstract class FooTests {
/* tests go here */
}
[TestFixture, SetCulture ("en-GB")] public class FooTestsEN : FooTests {}
[TestFixture, SetCulture ("pl-PL")] public class FooTestsPL : FooTests {}
Ideally, I shouldn't have to create these classes and instead use something like:
[assembly: SetCulture ("en-GB")]
[assembly: SetCulture ("pl-PL")]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
不幸的是,这现在不可能,但计划在未来实现。
你也可以这样做。
也许这是你更喜欢的?
Unfortunatelly this isn't possible now but is planned for future.
You can also do this.
Maybe that's something you would prefer?
NUnit 的
SetCultureAttribute
将一种区域性应用于测试,但(尚)不支持多种区域性。您可以通过将
TestCaseAttribute
与语言代码结合使用并手动设置区域性来解决此问题:请注意,此单元测试对于
de
和da
将失败- 不同文化的测试非常重要:)NUnit's
SetCultureAttribute
applies one culture to a test, multiple cultures are not (yet) supported.You can work around this by using the
TestCaseAttribute
with language codes and setting the culture manually:Note that this unit test will fail for
de
andda
- testing for different cultures is really important :)如果您不介意切换,MbUnit 有这个该功能已使用近五年。
您可以在测试、夹具和装配级别应用
MultipleCulture
属性。If you don't mind switching, MbUnit has had this feature for nearly five years now.
You can apply the
MultipleCulture
attribute at the test, fixture and assembly levels.如果有人正在寻找如何做到这一点 - 由于 NUnit 没有内置它,我这样做了......
If anyone is looking for how to do this - as NUnit doesnt have it built in, I did this...