SORU
12 EKİM 2012, Cuma


Nasıl belirli bir yöntem kullanarak Mockito çağrıldı doğrulamak için?

Nasıl bir yöntem olduğunu doğrulamak içindeğilbir nesnenin bağımlılık çağırdı?

Örneğin:

public interface Dependency {
    void someMethod();
}

public class Foo {
    public bar(final Dependency d) {
        ...
    }
}

Foo ile test:

    public class FooTest {
        @Test
        public void dependencyIsNotCalled() {
            final Foo foo = new Foo(...);
            final Dependency dependency = mock(Dependency.class);
            foo.bar(dependency);
            // verify here that someMethod was not called??
        }
    }

CEVAP
12 EKİM 2012, Cuma


Daha da anlamlı :

import static org.mockito.Mockito.*;

// ...

verify(dependency, never()).someMethod()

Bu özellik belgelerine §4 "Verifying exact number of invocations / at least x / never" never javadoc here var.

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • AmeriiK_HD

    AmeriiK_HD

    16 AĞUSTOS 2012
  • disneychannel

    disneychanne

    19 ŞUBAT 2006
  • xSammyJoe1

    xSammyJoe1

    19 Temmuz 2011