سؤال

here is my test class..

  @RunWith(SpringJUnit4ClassRunner.class)
   @ContextConfiguration(loader=AnnotationConfigContextLoader.class)
   public Testclass {
     @Autowired
     private VClasss vclass;
       .....
       .....

     @Before
     public void setup() {
       //mockito.when.(vClass.isvalid()).thenReturn(true);

    }
    @After
    public void verify( {
     Mockito.verify(vCLass, VerificationModeFactory.times(1)).isValid();
     Mockito.reset();
    }


   @Test
   public void test1() {
     //set up test which will call the mock isValid method

   }

   @Test
   public void test1() {
    //set up test which will call the mock isValid method
   }


   @Configuration
   static class configurationForTest {
    @Bean
     public VClass vClass() {
      return mockito.mock(VClass.class);
     }
   }

My question is that when i set this up, first test passes, as the verify is correct isValid was called once, however the second fails as now verify complains asking that isValid was called twice.. I expected the reset method on mockito to reset the call count afetr each test..

Does anybody have any suggestions?

هل كانت مفيدة؟

المحلول

You don't pass any mock to reset. The line should be

Mockito.reset(vClass);
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top