Note that there are some explanatory texts on larger screens.

plurals
  1. POCustom Junit runner doesn't ignore tests with Assume.assumeTrue(someFalseCondition)
    primarykey
    data
    text
    <p>I have written a custom Junit runner to have control on how to run Parameterized Tests. Below is the source code for it.</p> <p>The problem is that now the class extending from it doesn't honor Assume.assumeTrue(someFalseCondition). Instead of the test being ignored it fails with exception like this</p> <pre><code>org.junit.internal.AssumptionViolatedException: got: &lt;false&gt;, expected: is &lt;true&gt; at org.junit.Assume.assumeThat(Assume.java:70) at org.junit.Assume.assumeTrue(Assume.java:39) at org.terracotta.tests.base.AbstractTestBase.setUp(AbstractTestBase.java:68) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193) </code></pre> <p>Is there anything i am missing in this class below.</p> <pre><code>public class TcTestRunner extends Suite { /** * Annotation for a method which provides parameters to be injected into the test class constructor by * &lt;code&gt;Parameterized&lt;/code&gt; */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) public static @interface Configs { // Empty Annotation } private class TestClassRunnerForParameters extends BlockJUnit4ClassRunner { private final int fParameterSetNumber; private final List&lt;TestConfig&gt; fParameterList; TestClassRunnerForParameters(Class&lt;?&gt; type, List&lt;TestConfig&gt; parameterList, int i) throws InitializationError { super(type); fParameterList = parameterList; fParameterSetNumber = i; } @Override public Object createTest() throws Exception { return getTestClass().getOnlyConstructor().newInstance(computeParams()); } private TestConfig computeParams() throws Exception { try { return fParameterList.get(fParameterSetNumber); } catch (ClassCastException e) { throw new Exception(String.format("%s.%s() must return a Collection of arrays.", getTestClass().getName(), getParametersMethod(getTestClass()).getName())); } } @Override protected String getName() { return String.format(fParameterList.get(fParameterSetNumber).getConfigName()); } @Override protected String testName(final FrameworkMethod method) { return String.format("%s[%s]", method.getName(), fParameterList.get(fParameterSetNumber).getConfigName()); } @Override protected void validateConstructor(List&lt;Throwable&gt; errors) { validateOnlyOneConstructor(errors); } @Override protected Statement classBlock(RunNotifier notifier) { return childrenInvoker(notifier); } } private final ArrayList&lt;Runner&gt; runners = new ArrayList&lt;Runner&gt;(); /** * Only called reflectively. Do not use programmatically. */ public TcTestRunner(Class&lt;?&gt; klass) throws Throwable { super(klass, Collections.&lt;Runner&gt; emptyList()); List&lt;TestConfig&gt; parametersList = getParametersList(getTestClass()); for (int i = 0; i &lt; parametersList.size(); i++) runners.add(new TestClassRunnerForParameters(getTestClass().getJavaClass(), parametersList, i)); } @Override protected List&lt;Runner&gt; getChildren() { return runners; } @SuppressWarnings("unchecked") private List&lt;TestConfig&gt; getParametersList(TestClass klass) throws Throwable { return (List&lt;TestConfig&gt;) getParametersMethod(klass).invokeExplosively(null); } private FrameworkMethod getParametersMethod(TestClass testClass) throws Exception { List&lt;FrameworkMethod&gt; methods = testClass.getAnnotatedMethods(Configs.class); for (FrameworkMethod each : methods) { int modifiers = each.getMethod().getModifiers(); if (Modifier.isStatic(modifiers) &amp;&amp; Modifier.isPublic(modifiers)) return each; } throw new Exception("No public static parameters method on class " + testClass.getName()); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload