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

  • Flash CS6 Video Tutorials for Beginners (Actionscript 3 Gaming)

    Flash CS6 Vi

    14 EYLÜL 2012
  • Samvith V Rao

    Samvith V Ra

    20 EKİM 2006
  • Thom Hall

    Thom Hall

    24 Kasım 2006