java - Is Expectations redundant if I have Verifications in my test? -


i'm confused purpose of , difference between expectations , verifications. e.g.

@tested fooserviceimpl fooservice; @injectable foodao foodao;  @test public void callsfoodaodelete() throws exception {     new expectations() {{         foodao.delete(withequal(1l)); times = 1;     }};      fooservice.delete(1l);      new verifications() {{         long id;         foodao.delete(id = withcapture()); times = 1;         assert.assertequals(1l, id);     }}; } 

first of all, please let me know if test poorly written/thought out.

second, question: expectations section seems redundant me, , can't come example wouldn't be.

the purpose of expectations allow test record expected results mocked methods and/or constructors, needed code under test.

the purpose of verifications allow test verify expected invocations mocked methods and/or constructors, made code under test.

so, normally, test wouldn't both record and verify same expectation (where "expectation" specifies set of invocations mocked methods/constructors expected occur when code under test exercised).

with in mind, example test this:

@tested fooserviceimpl fooservice; @injectable foodao foodao;  @test public void callsfoodaodelete() throws exception {     fooservice.delete(1l);      new verifications() {{ foodao.delete(1l); }}; } 

Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -