3
我有使用泽西2依赖注入单元测试
ResourceConfig config = new ResourceConfig()
.packages("controller", "exception")
.register(new MyDIBinder());
哪里MyDIBinder是这样
@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控制器包含的所有绑定(例如
AccountDaoImpl accountDaoImpl = new AccountDaoImpl();
bind(accountDaoImpl).to(AccountDao.class);
)
现在我想为这个控制器编写一个单元测试,是否有可能将整个AccountController实例及其所有传递依赖注入到测试中?
喜欢的东西
@Inject
AccountController accountController;
谢谢你的回答!什么是TestBinder? – andreybavt
这是我用来测试我的例子的活页夹。它只包含一个简单的服务绑定。对你而言,这将是MyDIBinding –
@peeskillet请使用TestBinder示例完成此响应。 – 4F2E4A2E