Spring 引导项目的 JUnit 和 Mockito 依赖项
JUnit and Mockito Dependencies for Spring Boot Project
我正在尝试使用 JUnit 和 Mockito 对我的 spring 引导项目进行 运行 单元测试,但我很难弄清楚如何在我的 spring 中设置依赖项我的 gradle 项目的 build.gradle 文件。这是 build.gradle 文件:
plugins {
id 'org.springframework.boot' version '2.2.2.RELEASE'
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
id 'org.flywaydb.flyway' version '7.1.1'
id 'java'
id 'war'
}
targetCompatibility = 1.11
sourceCompatibility = 1.11
repositories {
mavenLocal()
mavenCentral()
jcenter()
maven {
url = uri('https://repo.maven.apache.org/maven2/')
}
}
flyway {
url = System.getenv('HW_DATABASE_URL')
user = System.getenv('HW_DATABASE_USER')
password = System.getenv('HW_DATABASE_PASSWORD')
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-mail'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
implementation 'org.apache.tiles:tiles-core:3.0.8'
implementation 'org.apache.tiles:tiles-jsp:3.0.8'
implementation 'javax.servlet:jstl:1.2'
implementation 'mysql:mysql-connector-java:8.0.18'
implementation 'org.hibernate:hibernate-core:5.4.9.Final'
implementation 'org.hibernate:hibernate-entitymanager:5.4.9.Final'
implementation 'javax.xml.bind:jaxb-api:2.3.1'
implementation 'org.springframework.security:spring-security-taglibs:5.2.1.RELEASE'
implementation 'com.googlecode.owasp-java-html-sanitizer:owasp-java-html-sanitizer:20190610.1'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.11.3'
providedCompile 'org.apache.tomcat.embed:tomcat-embed-jasper'
compile 'org.apache.commons:commons-text:1.9'
compile 'commons-validator:commons-validator:1.7'
compile 'org.flywaydb:flyway-core:7.1.1'
compile 'org.springdoc:springdoc-openapi-ui:1.2.32'
testCompile 'junit:junit:4.13.1'
testCompile 'org.mockito:mockito-core:3.6.48'
}
现在我收到错误“无法解析 org.mockito:mockito-core:3.6.48”,我什至不知道我是否从中下载了正确的 Mockito 文件夹https://github.com/mockito/mockito/releases。因此,截至目前,我的 junit 或 mockito 导入中的 none 已被识别。如有任何帮助,我们将不胜感激。
问题是 Maven 存储库中不存在 Mockito 的版本。 Mockito 的最新版本是 3.6.28。签入此页面 Maven Repository
我正在尝试使用 JUnit 和 Mockito 对我的 spring 引导项目进行 运行 单元测试,但我很难弄清楚如何在我的 spring 中设置依赖项我的 gradle 项目的 build.gradle 文件。这是 build.gradle 文件:
plugins {
id 'org.springframework.boot' version '2.2.2.RELEASE'
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
id 'org.flywaydb.flyway' version '7.1.1'
id 'java'
id 'war'
}
targetCompatibility = 1.11
sourceCompatibility = 1.11
repositories {
mavenLocal()
mavenCentral()
jcenter()
maven {
url = uri('https://repo.maven.apache.org/maven2/')
}
}
flyway {
url = System.getenv('HW_DATABASE_URL')
user = System.getenv('HW_DATABASE_USER')
password = System.getenv('HW_DATABASE_PASSWORD')
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-mail'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
implementation 'org.apache.tiles:tiles-core:3.0.8'
implementation 'org.apache.tiles:tiles-jsp:3.0.8'
implementation 'javax.servlet:jstl:1.2'
implementation 'mysql:mysql-connector-java:8.0.18'
implementation 'org.hibernate:hibernate-core:5.4.9.Final'
implementation 'org.hibernate:hibernate-entitymanager:5.4.9.Final'
implementation 'javax.xml.bind:jaxb-api:2.3.1'
implementation 'org.springframework.security:spring-security-taglibs:5.2.1.RELEASE'
implementation 'com.googlecode.owasp-java-html-sanitizer:owasp-java-html-sanitizer:20190610.1'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.11.3'
providedCompile 'org.apache.tomcat.embed:tomcat-embed-jasper'
compile 'org.apache.commons:commons-text:1.9'
compile 'commons-validator:commons-validator:1.7'
compile 'org.flywaydb:flyway-core:7.1.1'
compile 'org.springdoc:springdoc-openapi-ui:1.2.32'
testCompile 'junit:junit:4.13.1'
testCompile 'org.mockito:mockito-core:3.6.48'
}
现在我收到错误“无法解析 org.mockito:mockito-core:3.6.48”,我什至不知道我是否从中下载了正确的 Mockito 文件夹https://github.com/mockito/mockito/releases。因此,截至目前,我的 junit 或 mockito 导入中的 none 已被识别。如有任何帮助,我们将不胜感激。
问题是 Maven 存储库中不存在 Mockito 的版本。 Mockito 的最新版本是 3.6.28。签入此页面 Maven Repository