I\'ve found a useful article that explains how to make Jersey to use SLF4J instead of JUL. Now my unit test looks like (and it works perfectly):
public class
What it sounds like is you'd want the JUL/SLF4J configuration handle before JUnit starts testing so it could be covered for all tests? Here's a way you could do that.
Output
MySuite.init()
MySuite()
getSuiteTests()
MyTest.init()
MyTest()
test()
Code
@RunWith(AbstractTestSuite.TestSuiteRunner.class)
public abstract class AbstractTestSuite {
public static class TestSuiteRunner extends Suite {
public TestSuiteRunner(Class> klass) throws Exception {
super(klass, ((Class extends AbstractTestSuite>) klass).newInstance().getSuiteClasses());
}
}
public Class>[] getSuiteClasses() {
List> all = new ArrayList>();
for (Class> testClass : getSuiteTests()) {
all.add(testClass);
}
return all.toArray(new Class>[0]);
}
protected abstract Iterable> getSuiteTests();
}
public class MySuite extends AbstractTestSuite {
public static class MyTest {
static {
System.out.println("MyTest.init()");
}
public MyTest() {
System.out.println("MyTest()");
}
@Test
public void test() {
System.out.println("test()");
assertTrue(true);
}
}
static {
System.out.println("MySuite.init()");
}
public MySuite() {
System.out.println("MySuite()");
}
@Override
protected Iterable> getSuiteTests() {
System.out.println("getSuiteTests()");
return Arrays.asList(new Class>[] {MyTest.class});
}
}