我正在尝试构建一个Sping Boot 应用程序,但是我无法运行我的测试。看起来它们是因为我的build.gradle而失败的,但是在尝试修复它2天后,我想我可能会尝试询问这里是否有人可以提供帮助。https://scans.gradle.com/s/m7diapblkqpxk/deprecations
build.gradle:
plugins {
id 'org.springframework.boot' version '3.2.0'
id 'io.spring.dependency-management' version '1.1.4'
id 'java'
}
group = 'com.fitnessforge'
version = '0.0.1-SNAPSHOT'
java {
sourceCompatibility = '20'
}
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa:3.1.2'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'com.mysql:mysql-connector-j:8.2.0'
implementation 'javax.persistence:javax.persistence-api:2.2'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
annotationProcessor 'org.projectlombok:lombok'
testImplementation('org.springframework.boot:spring-boot-starter-test:2.7.14') {
exclude group: 'junit'
}
testImplementation 'org.junit.jupiter:junit-jupiter-api'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
testImplementation 'org.springframework.security:spring-security-test:6.1.2'
}
tasks.named('bootBuildImage') {
builder = 'paketobuildpacks/builder-jammy-base:latest'
}
test {
useJUnitPlatform()
testFramework {
useJUnit()
}
}
字符串
用户存储库测试:
package com.fitnessforge.repository;
import com.fitnessforge.FitnessForgeApplication;
import com.fitnessforge.model.User;
import com.fitnessforge.repository.UserRepository;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@SpringBootTest
public class UserRepositoryTest {
@Autowired
private UserRepository userRepository;
@Test
public void testSaveUser() {
// Erstelle einen neuen Benutzer
User user = new User();
user.setUsername("testUser");
user.setPassword("testPassword");
user.setRole("Client");
// Speichere den Benutzer in der Datenbank
User savedUser = userRepository.save(user);
// Überprüfe, ob der Benutzer korrekt gespeichert wurde
assertNotNull(savedUser.getId());
assertEquals("testUser", savedUser.getUsername());
assertEquals("testPassword", savedUser.getPassword());
assertEquals("Client", savedUser.getRole());
}
}
型
更改build.gradle测试部分:
test {
useJUnitPlatform()
}
1条答案
按热度按时间guykilcj1#
我也面临着同样的警告,我所做的就是将
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
添加到依赖项部分。这已经在eclipse和gradle的github repos上建议了这里和这里。