1

I am trying to create test, that takes something from DB and compare values.

I have class and method:

@RunWith(SpringRunner.class) @SpringBootTest() @ActiveProfiles("dev") public class HibernateDataTest { @Autowired private UserRepository userRepository; @Autowired private ItemRepository itemRepository; @Test public void testData() { User u = userRepository.findByEmail("[email protected]"); Item item = createItem(u); Item id = itemRepository.save(item); assert(...); } 

However, this keep complaining:

Could not open ServletContext resource [/application.properties]

I have datasource defined for hibernate, that takes properties from application.properties file.

My structure is:

-app -src/main/java -src/main/resources -src/test/java -src/test/resources 

How can i link the application.properties file in this test class/method?

Thanks for help!

3
  • To take application.properties from main folder try add @TestPropertySource("classpath:application.properties") to your test class. Commented Nov 8, 2018 at 10:47
  • this throws same error Commented Nov 8, 2018 at 10:56
  • could you please sepcify the package of the test and the package of the main class (the class with @SpringBootApplication) ? If you run spring boot test like this, this kind of information becomes crucial Commented Nov 8, 2018 at 11:41

1 Answer 1

1

Add a properties file named 'application-dev.properties' in the following path:

src/test/resources 

This should work

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.