I have a client side java application which runs on Multiple OS.
I want to test a logic which gives different expectations when run in different OS.
For e.g when i run on Windows the logic will pass and when i run on OSX the logic will throw an exception.
I can write two separate tests and execute only one using separate build profiles for different OS but is it possible to write a single junit test which will behave differently under different OS. ?
For OSX i want to annotate the test with exception as expectation and For Windows normal logic should work. Is it possible in Junit that at runtime the expectations differ under certain circumstances ?
Best Regards,
Saurav
JUnit is a unit testing open-source framework for the Java programming language. Java Developers use this framework to write and execute automated tests. In Java, there are test cases that have to be re-executed every time a new code is added. This is done to make sure that nothing in the code is broken.
You use an assert method, provided by JUnit or another assert framework, to check an expected result versus the actual result. These method calls are typically called asserts or assert statements.
Benefits of using JUnitJUnit can help you keep your code organized and easy to read. JUnit can help you detect and fix errors in your code. JUnit can help you improve the quality of your software. JUnit can help you work more efficiently and improve your testing process.
with System.getProperty("os.name")
you can check which operating system you are on, then you can use conditional running to exclude the test cases you don't need on a specific operating system, e.g.
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" );
}
}
source: code affine
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With