mardi 19 juin 2018

Spring Boot Test is not using test properties

I Am using spring boot 2.0.1 , but when I perform the test, it seems to start, before the test class, also the main class. In my main class I use spring cloud config, discovery service and kafka. I have this test class:

@RunWith(SpringRunner.class)
@SpringBootTest
@TestPropertySource(locations = "classpath:bootstrap-test.properties")
@ActiveProfiles("test")
public class DaemonLogServiceTest {

@Autowired
private LogService logService;

@Before
public void setUp() {
    ResultLog log = new ResultLog();
    log.setNumberOfRowsProcessed(10);
    log.setLastCodOperProcessed(1000);
    log.setStatus(Status.SUCCESS.name());
}

@Test
public void whenOperationsProcessedThenLog() {
    logService.newActivity(10, 1000L, Status.SUCCESS);
    ResultLog log = logService.saveActivity();
    Assert.assertNotNull(log);
}

}

When I run it, it seems to start the Main method (not from test) that uses Kafka and Spring cloud discovery. Here is the output:

018-06-19 14:45:01.397 ERROR 17124 --- [           main] o.s.boot.SpringApplication               : Application run failed
java.lang.IllegalStateException: Failed to load ApplicationContext

at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:125)
at []
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'spring.kafka.bootstrap-servers' in value "${spring.kafka.bootstrap-servers}"

I only use Kafka in the main application, not in test classes. My property file is:

spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.url=jdbc:h2:mem:db;DB_CLOSE_DELAY=-1
spring.datasource.username=sa
spring.datasource.password=sa
spring.datasource.schema=classpath:schema.sql
daemon.delay=2000
spring.cloud.discovery.enabled = false
spring.cloud.config.discovery.enabled = false
spring.cloud.config.enabled = false
eureka.client.enabled=false
spring.profiles.active=test

Aucun commentaire:

Enregistrer un commentaire