Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPE with Junit5, SLF4J (log4j2) and Spring Boot Test #6

Open
vguna opened this issue Aug 31, 2018 · 2 comments
Open

NPE with Junit5, SLF4J (log4j2) and Spring Boot Test #6

vguna opened this issue Aug 31, 2018 · 2 comments
Assignees

Comments

@vguna
Copy link

vguna commented Aug 31, 2018

Just tried the following:

@ExtendWith(SpringExtension.class)
@SpringBootTest(
        classes = { Bla.class },
        webEnvironment = WebEnvironment.NONE)
@ActiveProfiles("test")
@LogCollectorExtension
public class FooTest {

...
    Logger logger = LoggerFactory.getLogger(Foo.class);
    JUnit5LogCollector collector = new JUnit5LogCollector(logger);
...

    @Test
    public void testFoo() {

        doSomethingWithFoo();

        // NPE happens here
        collector.getLogs().stream().forEach(log -> System.out.println(log));
    }
...
}

It dies with:

java.lang.NullPointerException
	at dk.bitcraft.lc.Log4j2Collector.getResult(Log4j2Collector.java:41)
	at dk.bitcraft.lc.JUnit5LogCollector.getLogs(JUnit5LogCollector.java:28)
	at com.acme.FooTest.testFoo(FooTest.java:131)

Seems like the appender in Log4j2Collector isn't properly initialized. Maybe somehow setup() isn't called properly?

@haasted haasted self-assigned this Aug 31, 2018
@rbachlec
Copy link

rbachlec commented May 7, 2019

Same problem here.

I found out that the @LogCollectorExtension annotation is ignored as soon as there is another @ExtendWith annotation. That means that the collector is not initialized.

That would not be that big problem if @JUnit5LogCollectorExtension wouldn't be package scoped so that it could be used directly with a present @ExtendWith annotation.

@sfdc-slumos
Copy link

Anyone have a workaround for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants