from old JUnit to modern JUnit

  • View
    4.631

  • Download
    4

Embed Size (px)

DESCRIPTION

関西Javaエンジニアの会'13 7月度の発表資料です。

Text of from old JUnit to modern JUnit

  • 1. from old JUnit to modern JUnit Java'13 7 @irof
  • 2. @irof ======== * * TDD * Java, Jenkins * Groovy, Gradle, Git Java, hoge, Jenkins
  • 3. Java1.47
  • 4. JUnit
  • 5. JUnit JUnit JUnit4
  • 6. JUnit
  • 7.
  • 8. xUnit IDE, , CI, , , etc...
  • 9. TestNG
  • 10. JUnit JUnit JUnit4
  • 11.
  • 12. F.I.R.S.T. Fast - Independent - Repeatable - Self-Validating - Timely -
  • 13. A-TRIP Automatic - Thorough - Repeatable - Independent - Professional -
  • 14.
  • 15.
  • 16.
  • 17.
  • 18. SlideShare
  • 19.
  • 20.
  • 21. 4xUTP
  • 22. Four-Phase Test @Test public void hoge() { Hoge sut = new Hoge(); String actual = sut.hoge(); assertThat(actual, is("fuga")); } setup exercise verify
  • 23. JUnit JUnit JUnit4
  • 24. JUnit
  • 25. JUnit 3 public class JUnit3Test extends TestCase { public void testHoge() { assertEquals(2, 1); } }
  • 26. JUnit 4 public class JUnit4Test { @Test public void hoge() { assertThat(1, is(2)); } }
  • 27. TestCase test @Test assertThat JUnit3 to JUnit4
  • 28. TestCase Java
  • 29. test testtypo
  • 30. assertThat Matcher
  • 31. assertThatJUnit4.4Assert hamcrest JUnit3 AssertionError
  • 32. JUnit4.4 4.4 - assertThat, Theories 4.7 - Rule(MethodRule) 4.8 - Categories 4.9 - TestRule 4.10 - RuleChain 4.11 - FixMethodOrder
  • 33. JUnit JUnit JUnit4
  • 34. JUnit4
  • 35. JUnit4 Matcher Rule Runner
  • 36. Matcher describeTo/describeMismatch describeMismatchhamcrest1.21.3 JUnit1.1
  • 37. Matcher assertThat(today, is(dateOf(2013, 2, 3))); java.lang.AssertionError: Expected: is "2013/02/03" but: "2013/07/31" at org.hamcrest.MatcherAssert.assertThat(MatcherAssert at org.junit.Assert.assertThat(Assert.java:865) at org.junit.Assert.assertThat(Assert.java:832) at JUnit4Test.hoge(JUnit4Test.java:24) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native describeMismatch describeTo
  • 38.
  • 39. Rule ExpectedException @Rule@ClassRule @Rule
  • 40. Rule Rule LogRule TestWatcher starting/finished succeeded/failed/skipped
  • 41.
  • 42. old Exception Test @Test public void hoge() { try { sut.hoge(); fail(); } catch(NullPointerException e) { assertEquals("", e.getMessage()); } }
  • 43. modern Exception Test @Test(expected = NullpointerException.class) public void hoge() { sut.hoge(); } k
  • 44. modern Exception Test @Rule public ExpectedException thrown = ExpectedException.none(); @Test public void hoge() { thrown.expect(NullPointerException.class); thrown.expectMessage(""); sut.hoge(); }
  • 45. modern Exception Test fail try-catch Matcher
  • 46. Rule
  • 47. Runner JUnit Enclosed Parameterized Theories Suite Categories
  • 48. Runner Arquillian WebJUnit SpringTest ApplicationContext
  • 49. Runner TestNG
  • 50. Web Ja