I am using spring-boot-1.5. Is there any way to load application.properties in src/test/resources during the unit test? I know how to load it using integration test we can use @SpringBootTest or @ContextConfiguration but I would like to use application.properties during unit test.
Let me explain my scenario a bit,
@SpringBootApplication(exclude = { MongoAutoConfiguration.class, MongoDataAutoConfiguration.class })
@EnableHypermediaSupport(type = EnableHypermediaSupport.HypermediaType.HAL)
public class BookBackendApplication {
public static void main(String[] args) {
SpringApplication.run(BookBackendApplication.class, args);
}
}
@Service
public class BookService {
@Value("${book-list:ACTIVE}")
private List<String> bookList = new ArrayList<>();
@Value("${book-status:PURCHASING}")
private String bookStatus;
public BookResponse purchaseBook(BookRequest bookRequest) {
if(bookRequest.getStatus().equals(bookStatus)) { //Here getting NPE while executing unit test
....
}
}
}
UNIT TEST
@RunWith(SpringRunner.class)
public class BookServiceTest {
@InjectMocks
private BookService bookService;
@Test
public void testBookActivate() throws IOException {
BookResponse bookResponse = bookService.purchaseBook(bookRequest);
...
}
}
Properties are not loading while running this unit test so getting NPE in BookService.java. Is there any way to load src/test/resource/application.properties while running the unit test?
Any pointers or help would be really appreciable.