升级JUNIT 5后无单元测试

时间:2019-06-17 12:26:51

标签: java spring-boot jhipster junit5

我将jhipster项目从5.8.2版本升级到6.1.0。

然后,我通过以下链接升级单元测试的类:https://github.com/jhipster/jhipster-online/issues/107

启动时:

./gradlew test

没有启动单元测试...

UnitTest类的示例:

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.web.PageableHandlerMethodArgumentResolver;
import org.springframework.http.MediaType;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.Validator;

import javax.persistence.EntityManager;
import java.util.ArrayList;
import java.util.List;

import static  fr.project.app.web.rest.TestUtil.createFormattingConversionService;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.hasItem;
import static org.mockito.Mockito.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

/**
 * Integration tests for the {@Link WebServiceResource} REST controller.
 */
@SpringBootTest(classes = ProjectApp.class)
public class WebServiceResourceIntTest {

有我的build.gradle文件:

import org.gradle.internal.os.OperatingSystem

buildscript {
repositories {
    mavenLocal()
    mavenCentral()
    gradlePluginPortal()
    maven { url "http://repo.spring.io/plugins-release" }
}
dependencies {
    classpath "org.springframework.boot:spring-boot-gradle-plugin:${spring_boot_version}"
    classpath "io.spring.gradle:propdeps-plugin:0.0.10.RELEASE"
    //jhipster-needle-gradle-buildscript-dependency - JHipster will add additional gradle build script plugins here
}
}

test {
    useJUnitPlatform()
    exclude "**/*IT*", "**/*IntTest*", "**/*CucumberIT*"
    testLogging {
        events 'FAILED', 'SKIPPED'
    }
    // uncomment if the tests reports are not generated
    // see https://github.com/jhipster/generator-jhipster/pull/2771 and     https://github.com/jhipster/generator-jhipster/pull/4484
    // ignoreFailures true
    reports.html.enabled = false
}

repositories {
    mavenLocal()
    mavenCentral()
    jcenter()
    //jhipster-needle-gradle-repositories - JHipster will add additional     repositories
}

dependencies {
// import JHipster dependencies BOM
    implementation platform("io.github.jhipster:jhipster-    dependencies:${jhipster_dependencies_version}" )

// Use ", version: jhipster_dependencies_version, changing: true" if you want
// to use a SNAPSHOT release instead of a stable release
implementation group: "io.github.jhipster", name: "jhipster-framework"
....
implementation "org.springframework.boot:spring-boot-starter-cache"
testImplementation ("org.springframework.boot:spring-boot-starter-test") {
    exclude module: "junit"
    exclude group: "com.vaadin.external.google", module: "android-json"
}
testImplementation "org.springframework.security:spring-security-test"
testImplementation "org.springframework.boot:spring-boot-test"
testImplementation "org.junit.jupiter:junit-jupiter-engine"
testImplementation "org.junit.vintage:junit-vintage-engine"
testImplementation "org.assertj:assertj-core"
testImplementation "junit:junit"
testImplementation "org.mockito:mockito-core"
testImplementation "org.hamcrest:hamcrest-library"
testImplementation "com.h2database:h2"
//jhipster-needle-gradle-dependency - JHipster will add additional 
}

wrapper {
    gradleVersion = "5.4.1"
}

...

compileJava.dependsOn processResources
processResources.dependsOn bootBuildInfo

升级jhipster已自动修改此文件

请问您有个主意吗?

1 个答案:

答案 0 :(得分:1)

我必须添加:

classpath 'org.junit.platform:junit-platform-gradle-plugin:1.2.0'

构建脚本依赖项。