我有一个像这样的控制器。
现在我想为这个控制器编写一个单元测试,是否可能将整个AccountController实例及其所有传递依赖项注入测试中?
类似以下内容:
@Path("/")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class AccountController implements CRUDController<Long, Account> {
private AccountDao accountDao;
private AccountService accountService;
@Inject
public AccountController(AccountDao accountDao, AccountService accountService) {
this.accountDao = accountDao;
this.accountService = accountService;
}
...
我正在使用依赖注入来注入AccountDao和AccountService
ResourceConfig config = new ResourceConfig()
.packages("controller", "exception")
.register(new MyDIBinder());
我的DIBinder中包含了所有的绑定(例如
AccountDaoImpl accountDaoImpl = new AccountDaoImpl();
bind(accountDaoImpl).to(AccountDao.class);
现在我想为这个控制器编写一个单元测试,是否可能将整个AccountController实例及其所有传递依赖项注入测试中?
类似以下内容:
@Inject
AccountController accountController;