0

I have a class under test with jmock and I was making a change to it and expecting it to fail but it didn't. Before my change I had a alert() method that was getting called as expected and the test was passing. After I made the change my alert() method should no longer get called, however the unit test continued working! I checked it by putting a breakpoint and stepping through and it in fact does NOT call alert(), however jmock seems to think it does. Any ideas on how to figure out what's going on here?

Mockery context = new Mockery();
final NotifierInterface notifier = context.mock(NotifierInterface.class);

context.checking(new Expectations() {{
  oneOf(notifier).alert(with(any(String.class)));
  ...
}

analyzer = new Analyzer(notifier);
analyzer.run();

Thanks!

naumcho
  • 18,671
  • 14
  • 48
  • 59
  • 2
    I'm not too familiar with jMock, but the [documentation](http://jmock.org/getting-started.html) implies you need to call `context.assertIsSatisfied()` in order to verify the expectations. Are you calling this further along in your code? If not, your test will probably always pass. – andersschuller Jul 10 '13 at 18:56
  • Ah nice catch, that was it indeed! – naumcho Jul 10 '13 at 19:08
  • 1
    You can annotate the test class with @RunWith(JMock.class), this will invoke context.assertIsSatisfied() for you automatically. @andersschuller – Yugang Zhou Jul 14 '13 at 14:25

0 Answers0