我有一个服务类MyService
,它被定义并在控制器中使用,如下所示:
public interface MyService {
public String someMethod()
}
@Service("myService")
public class MyServiceImpl implements MyService {
public String someMethod() {
return "something";
}
}
@Controller
public class MyController {
@Autowired
public MyService myService;
@RequestMapping(value="/someurl", method=RequestMethod.GET)
public String blah () {
return myService.getsomeMethod();
}
}
我想为该方法编写一个测试用例someMethod
,但是,以下方法不起作用。如何在实现类中连接?
public class MyServiceImplTest {
@Autowired
private MyService myService;
@Test
public void testSomeMethod() {
assertEquals("something", myService.someMethod());
}
}