Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't find properties file when running gradle test

Tags:

java

junit

gradle

I am using gradle to build and test my application. I use the command

gradle test

But the testing, which works perfectly when run from within eclipse, fails when run using gradle. My test is defined below and the properties file that it cannot find is in both these folders:

/home/user/Development/git/myproject/src/main/java/com/mycompany/config /home/user/Development/git/myproject/src/test/resources

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(loader = AnnotationConfigContextLoader.class, classes = {      ApplicationConfig.class })
public class WebImportTest {
    @Resource
    private Environment env;

    @Autowired
    private JestClient jestClient;

my java configuration looks like so:

@Configuration
@ComponentScan({ "com.mycompany" })
@PropertySource("classpath:/com/mycompany/config/myproject.properties")
@Import(PersistenceConfig.class)
public class ApplicationConfig {

    @Resource
    private Environment env;

I am not experience enough in order to figure out what is the cause of this

: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

Why is the properties file not found?!

like image 499
Jes Chergui Avatar asked Mar 13 '14 12:03

Jes Chergui


People also ask

Where is application properties in Gradle project?

You will need to add the application. properties file in your classpath. If you are using Maven or Gradle, you can just put the file under src/main/resources . If you are not using Maven or any other build tools, put that under your src folder and you should be fine.


1 Answers

The properties file needs to go into src/main/resources/com/mycompany/config.

like image 181
Peter Niederwieser Avatar answered Sep 21 '22 14:09

Peter Niederwieser