Skip to content

Context caching across packages is prevented by using @AutoConfigure… on a test class #9282

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

Closed
wilkinsona opened this issue May 22, 2017 · 0 comments
Assignees
Labels
type: bug A general bug type: regression A regression from a previous release
Milestone

Comments

@wilkinsona
Copy link
Member

wilkinsona commented May 22, 2017

Context caching is not performed when two identically configured test classes are in different packages. For example:

package com.example.foo;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest
@AutoConfigureMockMvc
public class FooTests {

	@Test
	public void contextLoads() {
	}

}
package com.example.bar;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest
@AutoConfigureMockMvc
public class BarTests {

	@Test
	public void contextLoads() {
	}

}

The context will be loaded twice due to AutoConfigurationPackages$Registrar returning a PackageImport for the test class from determineImports(AnnotationMetadata). The test classes are in different packages (com.example.foo and com.example.bar) so this is enough to prevent the cache keys from matching.

The problem was introduced in 1.5 as part of the changes made in fa6a138 for #7953.

@wilkinsona wilkinsona added priority: high type: bug A general bug type: regression A regression from a previous release labels May 22, 2017
@wilkinsona wilkinsona added this to the 1.5.4 milestone May 22, 2017
@philwebb philwebb self-assigned this Jun 6, 2017
@snicoll snicoll modified the milestones: 1.5.4, 1.5.5 Jun 8, 2017
@wilkinsona wilkinsona marked this as a duplicate of #9694 Jul 21, 2017
sirkkalap added a commit to tmfg/digitraffic-marine that referenced this issue Jan 4, 2018
- spring-projects/spring-boot#7174
- spring-projects/spring-boot#9282
- Korjattu Spring Boot sovelluksen hierarkia niin, ettei tarvita
  EntityScan ja ComponentScan annotaatioita. Siirretty util -> meri.util.
- Siivottu turhia testejä pois
- Madallettu testiluokkien hierarkiaa
- Yhdenmukaistettu testicontextien parametrointia, jottei tarvita niin
  montaa eri kontekstia.
- Palautettu Datasource Bean osaksi sovellusta, jottei vaihdu eri
  testien käynnistyksessä Generic -> Hikari
-
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug type: regression A regression from a previous release
Projects
None yet
Development

No branches or pull requests

3 participants