我正在使用gradle来构建和测试我的应用程序。我使用命令
gradle test
但是当使用gradle运行时,在eclipse中运行时运行良好的测试会失败。我的测试定义如下,它找不到的属性文件位于这两个文件夹中:
/家庭/用户/开发/ GIT中/ myproject的/ SRC /主/ JAVA / COM / myCompany的/配置 /家庭/用户/开发/ GIT中/ myproject的/ SRC /测试/资源
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(loader = AnnotationConfigContextLoader.class, classes = { ApplicationConfig.class })
public class WebImportTest {
@Resource
private Environment env;
@Autowired
private JestClient jestClient;
我的java配置如下:
@Configuration
@ComponentScan({ "com.mycompany" })
@PropertySource("classpath:/com/mycompany/config/myproject.properties")
@Import(PersistenceConfig.class)
public class ApplicationConfig {
@Resource
private Environment env;
我没有足够的经验来弄清楚这是什么原因
:myproject is getting tests from [task ':test']
:compileJava
Note: /home/user/Development/git/myproject/src/main/java/com/mycompany/entities/generated/Keys.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
:processResources UP-TO-DATE
:classes
:instrument SKIPPED
:copyCoberturaDatafile SKIPPED
:compileTestJava
:processTestResources UP-TO-DATE
:testClasses
:test
com.mycompany.myProject.DBConnectionTest > initializationError FAILED
java.lang.Exception
com.mycompany.myProject.WebImportTest > testWebImport FAILED
java.lang.IllegalStateException
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException
Caused by: java.io.FileNotFoundException
为什么找不到属性文件?!
答案 0 :(得分:5)
属性文件需要进入src/main/resources/com/mycompany/config
。