I am attempting the testing for a sample spring project : http://ift.tt/1jtHq9p When I try invoking the controller classes for testing purpose I get the below error:
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'albumController' defined in file [D:\Docs_Tutorials\spring-music\spring-music\target\classes\org\cloudfoundry\samples\music\web\controllers\AlbumController.class]:
Unsatisfied dependency expressed through constructor argument with index 0 of type [org.cloudfoundry.samples.music.repositories.AlbumRepository]:
: No qualifying bean of type [org.cloudfoundry.samples.music.repositories.AlbumRepository] found for dependency:
expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {};
nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException:
Below is my JUnit test class :
@Category(IntegrationTest.class)
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration(classes = {WebMvcConfig.class,SpringApplicationContextInitializer.class})
public class EndPointsTesting {
@Autowired
private WebApplicationContext wac;
@Autowired
private AlbumRepository albumRepository;
private MockMvc mockMvc;
@Before
public void setup() {
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();
}
@Test
public void testEndPoints() throws Exception
{
this.mockMvc.perform(get("/albums"))
.andExpect(status().isOk())
.andExpect( content().contentType(org.springframework.http.MediaType.APPLICATION_JSON))
.andExpect(content().string("[{\"_class\": \"org.cloudfoundry.samples.music.domain.Album\",\"artist\": \"Test123\",\"title\": \"Test Title\",\"releaseYear\": \"2015\",\"genre\": \"Rock\" },{\"_class\": \"org.cloudfoundry.samples.music.domain.Album\",\"artist\": \"Test456\",\"title\": \"Test Title\",\"releaseYear\": \"2015\",\"genre\": \"Blues\" }]"));
}
}
Is there something wrong in the way I am attempting the integration test.Can someone help.
Aucun commentaire:
Enregistrer un commentaire