powermock/powermock

Custom runner delegate, "Notifications are not supported when all test-instances are created first"

Open

#660 建立於 2016年4月15日

在 GitHub 查看
 (7 留言) (0 反應) (0 負責人)Java (4,072 star) (585 fork)batch import
bugcomponent:junitcomponent:mockitogood first issue

描述

I'm trying to use PowerMockRunner with my own custom runner delegate that extends BlockJUnit4ClassRunner per the brief Wiki at https://github.com/jayway/powermock/wiki/JUnit_Delegating_Runner.

My custom runner delegate is simply this:

import org.junit.runners.BlockJUnit4ClassRunner;

public final class FooRunner extends BlockJUnit4ClassRunner {
  public FooRunner(final Class<?> klass) throws Exception {
    super(klass);
  }
  @Override
  public void run(final RunNotifier notifier) {
    super.run(notifier);
  }
}

And the corresponding unit test that makes use of my custom runner delegate with the @PowerMockRunnerDelegate annotation is this:

@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(FooRunner.class)
@PowerMockIgnore("javax.net.ssl.*")
public final class FooRunnerTestExample {
  public FooRunnerTestExample() {
    // Intentionally empty.
  }
  @Test
  public void fooTest() {
    // Intentionally empty.
  }
}

This runs fine, fooTest succeeds and test execution is funneled through my delegate.

However, in doing so, running with a delegate results in Powermock spewing these "errors" (warnings?) to System.err:

Notifications are not supported for behaviour ALL_TESTINSTANCES_ARE_CREATED_FIRST
Notifications are not supported for behaviour ALL_TESTINSTANCES_ARE_CREATED_FIRST
Notifications are not supported when all test-instances are created first!

There's no clear documentation on exactly what this means — further, I could be wrong, but in this use case I don't think this is a real problem that warrants complaints to System.err. In fact, using @PowerMockRunnerDelegate with Powermock's own org.powermock.modules.junit4.PowerMockRunnerDelegate.DefaultJUnitRunner results in the same System.err spew.

I conjecture the bug here is that these errors are mistakenly dumped to System.err given my use case. Even if this configuration is a "problem" there should at least be a way for Powermock users to suppress these messages.

I'm using JUnit 4.12 and Powermock 1.6.4.

貢獻者指南