JUnit içinde CollectionAssert? | Netgez.com
SORU
6 Temmuz 2009, PAZARTESİ


JUnit içinde CollectionAssert?

JUnit bir paralel CollectionAssert NUnit var mı?

CEVAP
6 Temmuz 2009, PAZARTESİ


Kullanarak JUnit 4.4 kullanabilirsiniz assertThat() birlikte Hamcrest code (merak etmeyin, bu sevk ile JUnit, gerek yok ekstra .jar) üretmek için karmaşık kendini tarif onayları dahil olanlar ameliyat koleksiyonlar:

import static org.junit.Assert.assertThat;
import static org.junit.matchers.JUnitMatchers.*;
import static org.hamcrest.CoreMatchers.*;

List<String> l = Arrays.asList("foo", "bar");
assertThat(l, hasItems("foo", "bar"));
assertThat(l, not(hasItem((String) null)));
assertThat(l, not(hasItems("bar", "quux")));
// check if two objects are equal with assertThat()

// the following three lines of code check the same thing.
// the first one is the "traditional" approach,
// the second one is the succinct version and the third one the verbose one 
assertEquals(l, Arrays.asList("foo", "bar")));
assertThat(l, is(Arrays.asList("foo", "bar")));
assertThat(l, is(equalTo(Arrays.asList("foo", "bar"))));

Otomatik olarak yüklenecektir iyi bir açıklama olacaktır bu yaklaşımı kullanarak başarısız olduğunda belirt.

Bunu PaylaÅŸ:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Jeb Corliss

    Jeb Corliss

    17 Kasım 2006
  • Rozetked | Обзоры

    Rozetked | Ð

    5 AÄžUSTOS 2011
  • The Amazing Atheist

    The Amazing

    20 Kasım 2006