我正在尝试使用Spock为我的Spring Boot 1.4.0编写一些测试,并且我的应用程序测试属性文件没有被选中.
我在我的gradle中有这个:
dependencies {
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-security')
compile('org.springframework.boot:spring-boot-starter-web')
compile 'org.codehaus.groovy:groovy-all:2.4.1'
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('org.spockframework:spock-spring:1.0-groovy-2.4') {
}
Run Code Online (Sandbox Code Playgroud)
然后我有这个
/ src目录/测试/常规/资源:
# JWT Key
jwt.key=MyKy@99
Run Code Online (Sandbox Code Playgroud)
最后我的Spock测试:
@SpringBootTest(classes = MyApplication.class, webEnvironment=SpringBootTest.WebEnvironment.RANDOM_PORT)
@TestPropertySource("application-test.properties")
public class TokenUtilityTest extends Specification {
@Autowired
private TokenUtility tokenUtility
def "test a valid token creation"() {
def userDetails = new User(username: "test", password: "password", accountNonExpired: true, accountNonLocked: true,
);
when:
def token = tokenUtility.buildToken(userDetails)
then:
token != null
}
}
Run Code Online (Sandbox Code Playgroud)
哪个测试这个类:
@Component
public class TokenUtility {
private static final Logger LOG …Run Code Online (Sandbox Code Playgroud)