Merge pull request #11549 from hmdrzsharifi/BAEL-4197
Bael 4197: Failed to Load Applicationcontext for Junit Test of Spring Controller
This commit is contained in:
+27
@@ -0,0 +1,27 @@
|
||||
package com.baeldung.xmlapplicationcontext;
|
||||
|
||||
import com.baeldung.xmlapplicationcontext.service.EmployeeService;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = XmlBeanApplication.class)
|
||||
//@ContextConfiguration(locations = "file:src/main/webapp/WEB-INF/application-context.xml")
|
||||
public class EmployeeServiceAppContextIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private EmployeeService service;
|
||||
|
||||
@Test
|
||||
public void whenContextLoads_thenServiceISNotNull() {
|
||||
assertThat(service).isNotNull();
|
||||
}
|
||||
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package com.baeldung.xmlapplicationcontext;
|
||||
|
||||
import com.baeldung.xmlapplicationcontext.service.EmployeeService;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = XmlBeanApplication.class)
|
||||
@ContextConfiguration(locations = "/test-context.xml")
|
||||
public class EmployeeServiceTestContextIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
@Qualifier("employeeServiceTestImpl")
|
||||
private EmployeeService serviceTest;
|
||||
|
||||
@Test
|
||||
public void whenTestContextLoads_thenServiceTestISNotNull() {
|
||||
assertThat(serviceTest).isNotNull();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user