我有一个在多个OS上运行的客户端Java应用程序。
我想测试在不同的OS上运行时给出不同期望的逻辑。
例如,当我在Windows上运行时,逻辑将通过,而当我在OSX上运行时,逻辑将引发异常。
我可以编写两个单独的测试,并针对不同的操作系统使用单独的构建配置文件仅执行一个测试,但是有可能编写一个单一的junit测试,该测试在不同的操作系统下表现会有所不同。?
对于OSX,我希望按预期对测试进行异常注释,对于Windows,正常的逻辑应该起作用。在Junit中,在某些情况下运行时的期望可能会有所不同吗?
最好的祝福,
绍拉夫
与System.getProperty("os.name")你可以检查你是哪种操作系统,那么你可以使用条件运行来排除你不需要特定的操作系统,例如在测试用例
public class SomeTest {
@Rule
public ConditionalIgnoreRule rule = new ConditionalIgnoreRule();
@Test
@ConditionalIgnore( condition = NotRunningOnWindows.class )
public void testFocus() {
// ...
}
}
public class NotRunningOnWindows implements IgnoreCondition {
public boolean isSatisfied() {
return !System.getProperty( "os.name" ).startsWith( "Windows" );
}
}
Run Code Online (Sandbox Code Playgroud)
来源:仿射代码
| 归档时间: |
|
| 查看次数: |
44 次 |
| 最近记录: |