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 when running test with junit Timeout rule #152

Open
gionn opened this issue Nov 18, 2020 · 1 comment
Open

NPE when running test with junit Timeout rule #152

gionn opened this issue Nov 18, 2020 · 1 comment

Comments

@gionn
Copy link

gionn commented Nov 18, 2020

Hi, I am in the middle of migrating an old Spring MVC 4.x application to Spring Boot 2.x.

I was using the upstream spring-test-dbunit that didn't get any updates recently.

I think I've found a bug related on how the test-context is handled when the Junit rule timeout is used:

11:04:33.493 DEBUG BaseDbUnitTest  - Starting test baseTest in SpringBootTestTest [Time-limited test]
11:04:33.509 INFO  TransactionContext  - Began transaction (1) for test context [DefaultTestContext@52cdebea testClass = SpringBootTestTest, testInstance = com.liberologico.cloudesire.cmw.test.SpringBootTestTest@68edb496, testMethod = baseTest@SpringBootTestTest, testException = [null], mergedContextConfiguration = [WebMergedContextConfiguration@1d248383 testClass = SpringBootTestTest, locations = '{}', classes = '{class com.liberologico.cloudesire.SpringBootCmw}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}', contextCustomizers = set[org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@343570b7, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@236e3f4e, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@152aa092, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@4cc8eb05, org.springframework.boot.test.context.SpringBootTestArgs@1], resourceBasePath = 'src/main/webapp', contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]], attributes = map['org.springframework.test.context.web.ServletTestExecutionListener.activateListener' -> true, 'org.springframework.test.context.web.ServletTestExecutionListener.populatedRequestContextHolder' -> true, 'org.springframework.test.context.web.ServletTestExecutionListener.resetRequestContextHolder' -> true]]; transaction manager [org.springframework.orm.jpa.JpaTransactionManager@5343ec9a]; rollback [true] [Time-limited test]
11:04:33.604 WARN  TestContextManager  - Caught exception while invoking 'beforeTestMethod' callback on TestExecutionListener [com.github.springtestdbunit.DbUnitTestExecutionListener@727eb8cb] for test method [public void com.liberologico.cloudesire.cmw.test.SpringBootTestTest.baseTest()] and test instance [com.liberologico.cloudesire.cmw.test.SpringBootTestTest@68edb496] [Time-limited test]
java.lang.NullPointerException: null
	at com.github.springtestdbunit.DbUnitRunner.loadDataset(DbUnitRunner.java:245)
	at com.github.springtestdbunit.DbUnitRunner.loadDataSets(DbUnitRunner.java:212)
	at com.github.springtestdbunit.DbUnitRunner.setupOrTeardown(DbUnitRunner.java:189)
	at com.github.springtestdbunit.DbUnitRunner.beforeTestMethod(DbUnitRunner.java:79)
	at com.github.springtestdbunit.DbUnitTestExecutionListener.beforeTestMethod(DbUnitTestExecutionListener.java:180)
	at org.springframework.test.context.TestContextManager.beforeTestMethod(TestContextManager.java:289)
	at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
	at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
	at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:61)
	at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:288)
	at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:282)
@gionn
Copy link
Author

gionn commented Nov 18, 2020

Sorry, I've digged deeper and found that the culprit was:

    @Rule
    public Timeout globalTimeout = new Timeout( 2, TimeUnit.MINUTES );

@gionn gionn changed the title NPE when running test with multiple superclasses NPE when running test with junit Timeout rule Nov 18, 2020
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

1 participant