Upgrade to Pro — share decks privately, control downloads, hide ads and more …

See the Truth

See the Truth

Un nouveau framework d'assertions en Java présenté à Devoxx France 2016

Code disponible: https://github.com/jeremiemartinez/truth_devoxx

Jeremie Martinez

April 21, 2016
Tweet

More Decks by Jeremie Martinez

Other Decks in Technology

Transcript

  1. Failure strategy 1. Si l’assert échoue on arrête le test

    et on le marque comme échoué. : Assert
  2. Failure strategy : Assume @Test
 public void should_test_super_new_feature() {
 assume().that(VERSION.SDK_INT)


    .isGreaterThan(VERSION.LOLLIPOP);
 
 // Some assertions only run on Lollipop
 }
  3. Failure strategy : Expect 3. Si l’expect échoue On continue

    le test et on accumule les échecs. À la fin du test, on fait le bilan.
  4. Failure strategy : Expect private final Expect EXPECT = Expect.create();


    private final ExpectedException thrown = ExpectedException.none();
 
 @Rule public final TestRule wrapper = (base, description) -> {
 Statement expected = EXPECT.apply(base, description);
 return thrown.apply(expected, description);
 };
  5. Failure strategy : Expect @Test
 public void should_convert() {
 Cart.Item

    item = new Cart.Item(1L, "Tomatoes", 3f);
 
 ItemDTO dto = convert(item);
 
 EXPECT.that(dto.description).isEqualTo("Tomatoes");
 EXPECT.that(dto.id).isEqualTo(1);
 EXPECT.that(dto.price).isEqualTo(3);
 }