2017-05-11 1 views
1

Je suis en train d'écrire une intégration pour Spring Boot l'applicationtests pour l'application de démarrage du printemps ne sont pas runned

import org.springframework.boot.SpringApplication; 
import org.springframework.boot.context.web.SpringBootServletInitializer; 
import org.springframework.boot.autoconfigure.SpringBootApplication; 
import org.springframework.boot.web.servlet.ServletRegistrationBean; 
import org.springframework.context.annotation.Bean; 
import org.springframework.context.annotation.ComponentScan; 

@SpringBootApplication 
@ComponentScan(basePackages = { "com.lapots.tree.model.web" }) 
public class TreeModelApplication extends SpringBootServletInitializer { 

    public static void main(String[] args) { 
     SpringApplication.run(TreeModelApplication.class, args); 
    } 

    @Bean 
    public ServletRegistrationBean servletRegistrationBean() throws Exception { 
     ServletRegistrationBean registrationBean = new ServletRegistrationBean(new RootServlet(), "/tree-model-app"); 
     registrationBean.setLoadOnStartup(1); 
     registrationBean.setAsyncSupported(true); 
     return registrationBean; 
    } 
} 

Le test ressemble à ce

import org.junit.jupiter.api.Test; 
import org.junit.jupiter.api.extension.ExtendWith; 
import org.springframework.boot.test.context.SpringBootTest; 
import org.springframework.test.context.junit.jupiter.SpringExtension; 
import org.springframework.web.client.RestTemplate; 

import static org.junit.jupiter.api.Assertions.assertEquals; 

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, 
     classes = TreeModelApplication.class) 
@ExtendWith(SpringExtension.class) 
public class TreeModelApplicationIntegrationTest { 
    private static final String PING_URL = "http://localhost:8080/tree-model-app/ping"; 

    private RestTemplate restTemplate = new RestTemplate(); 

    @Test 
    public void routerReturnsTrueOnPing() { 
     String response = restTemplate.getForObject(PING_URL, String.class); 
     assertEquals("false", response, "Ping response should be the same as expected."); 
    } 
} 

Cependant quand je lance gradlew test - rien ne se passe - construire réussie et les rapports sont vides. Quel est le problème?

Mon build.gradle est

buildscript { 
    ext { 
     springBootVersion = '2.0.0.BUILD-SNAPSHOT' 
    } 
    repositories { 
     mavenCentral() 
     maven { url "https://repo.spring.io/snapshot" } 
     maven { url "https://repo.spring.io/milestone" } 
    } 
    dependencies { 
     classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 
    } 
} 

apply plugin: 'java' 
apply plugin: 'war' 
apply plugin: 'org.springframework.boot' 
apply plugin: 'io.spring.dependency-management' 

version = '0.0.1-SNAPSHOT' 
sourceCompatibility = 1.8 

repositories { 
    jcenter() 
    maven { url "https://repo.spring.io/snapshot" } 
    maven { url "https://repo.spring.io/milestone" } 
    maven { url 'https://jitpack.io' } 
} 

dependencies { 
    compile('org.springframework.boot:spring-boot-starter-actuator') 
    compile('org.springframework.boot:spring-boot-starter-data-jpa') 
    compile('org.springframework.boot:spring-boot-starter-web') 
    compile('org.springframework.boot:spring-boot-starter-webflux') 
    compile('org.springframework.boot:spring-boot-starter-websocket') 
    compile('org.springframework.boot:spring-boot-starter-jetty') 

    runtime('org.springframework.boot:spring-boot-devtools') 

    testCompile('org.springframework.boot:spring-boot-starter-test') 
    testCompile("org.springframework:spring-test") 
    testCompile("org.junit.platform:junit-platform-runner:$junitPlatformVersion") 
    testCompile("org.junit.jupiter:junit-jupiter-engine:$junitJupiterVersion") 
    testCompile("org.junit.jupiter:junit-jupiter-api:$junitJupiterVersion") 
    testCompile("com.github.sbrannen:spring-test-junit5:1.0.0.M4") 
} 
+0

Est-ce correct l'importation @Test? Je m'attendais à voir org.junit.Test. On dirait que le printemps ne trouve pas de tests – kimy82

+0

Eh bien, j'utilise 'Junit5' donc je l'ai utilisé – lapots

+0

pouvez-vous exécuter les tests individuellement? Je veux dire de l'IDE – pvpkiran

Répondre

1

La question est donc plug-in gradle n'a pas été configuré pour exécuter jUnit 5 tests

Voici le conf nécessaire collé directement from JUnit5 website:

buildscript { 
    repositories { 
     mavenCentral() 
     // The following is only necessary if you want to use SNAPSHOT releases. 
     // maven { url 'https://oss.sonatype.org/content/repositories/snapshots' } 
    } 
    dependencies { 
     classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.0-M4' 
    } 
} 

apply plugin: 'org.junit.platform.gradle.plugin' 
0

Essayez d'ajouter cette @RunWith(SpringRunner.class) à la déclaration de classe de test

+2

c'est jUnit5, Runner est remplacé par @ExtendWith (SpringExtension.class) – Kotse