Created
March 10, 2011 17:26
-
-
Save barend/864506 to your computer and use it in GitHub Desktop.
A JUnit Runner that behaves like the default runner on Windows and ignores all tests on other operating systems.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//http://www.apache.org/licenses/LICENSE-2.0 | |
package nl.fnord.junit; | |
import org.junit.runner.notification.RunNotifier; | |
import org.junit.runners.BlockJUnit4ClassRunner; | |
import org.junit.runners.model.FrameworkMethod; | |
import org.junit.runners.model.InitializationError; | |
/** | |
* A JUnit {@code Runner} that behaves like the default runner on Windows and | |
* ignores all tests on other operating systems. | |
* <h3>Usage:</h3> | |
* <pre> | |
* @RunWith(OnlyOnWindowsRunner.class) | |
* public class SomeClassTest { | |
* @Test | |
* public void testSomethingWindowsSpecific() { | |
* // etc. | |
* } | |
* } | |
* </pre> | |
*/ | |
public class OnlyOnWindowsRunner extends BlockJUnit4ClassRunner { | |
public OnlyOnWindowsRunner(Class<?> klass) throws InitializationError { | |
super(klass); | |
} | |
@Override | |
protected void runChild(FrameworkMethod method, RunNotifier notifier) { | |
isWindows() | |
? super.runChild(method, notifier) | |
: notifier.fireTestIgnored(getDescription); | |
} | |
/** | |
* @return whether the host OS is windows. | |
*/ | |
private boolean isWindows() { | |
// This can probably be improved. | |
return System.getProperty("os.name").indexOf("Windows") > -1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment