目前我有以下build.gradle文件:
apply plugin: 'java'
repositories {
mavenCentral()
}
sourceSets {
main {
java {
srcDir 'src/model'
}
resources {
srcDir 'images/model'
}
}
test {
java {
srcDir 'tests/model'
}
resources {
srcDir 'images/model' // <=== NOT WORKING
}
}
}
dependencies {
compile files('libs/mnist-tools.jar', 'libs/gson-2.2.4.jar')
runtime fileTree(dir: 'libs', include: '*.jar')
testCompile group: 'junit', name: 'junit', version: '4.+'
}
Run Code Online (Sandbox Code Playgroud)
我的存储库如果在这里:https://github.com/quinnliu/WalnutiQ
我的49个测试中有4个失败,因为文件夹"tests/model"中的测试需要文件夹"images/model"中的文件.如何正确添加资源?谢谢!
我有一些带有注释的类@RestController
,我正在尝试使用MockMvc
该类进行测试.端点从Web应用程序正确响应,但在运行测试时出现以下错误(来自IntelliJ IDEA):
java.lang.IllegalArgumentException: Could not resolve placeholder
'spring.data.rest.base-path' in string value "${spring.data.rest.base-path}/whatever"
Run Code Online (Sandbox Code Playgroud)
这是application.properties
文件的样子:
spring.data.rest.base-path=/api
spring.profiles.active=dev
...
Run Code Online (Sandbox Code Playgroud)
我还有一个application-dev.properties
带有附加(不同)属性的文件.
这是测试类的注释方式:
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Application.class)
@WebIntegrationTest // Also tried: @WebAppConfiguration
@ActiveProfiles("dev")
// Also tried: @PropertySource("classpath:application.properties")
// Also tried: @TestPropertySource("classpath:application.properties")
public class MyRestControllerTest {
...
}
Run Code Online (Sandbox Code Playgroud)
另一方面,这是REST控制器的实现方式(使用有问题的属性):
@RestController
@RequestMapping("${spring.data.rest.base-path}/whatever")
public class MyRestController {
...
}
Run Code Online (Sandbox Code Playgroud)
这就是应用程序主类的外观:
@SpringBootApplication(scanBasePackages = {...})
@EnableJpaRepositories({...})
@EntityScan({...})
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
最后,这是项目结构的(子集): …