Tuesday 15 March 2011

java - JMockit withCapture not working -


Verification in jmockit with an object capture does not work much. Any help?

  @ Injection Personal API _api; @Tested Private ServiceImpl _service; @Test Public Zero Test () {New verification () {{VirtualUser user; _api.add (user = withCapture ()); Assert.assertEquals ("1", user.getId ()); Assert.assertEquals ("user", user.getUsername ()); }}; _service.add ("1", "user"); }   

Exception: zero indicator in user.getId ().

Verification block ( new verification () {...} ) test After the code is executed are about to arrive. In the example test, verification is executed first, so there is nothing to capture in the user variable at that moment, therefore, it remains null just verification Transfer the block to the end of the examination method.

No comments:

Post a Comment