JUnit

Install ?

https://github.com/junit-team/junit4/wiki/Download-and-Install

https://github.com/melonq/junit_test

 

Assertion

Assertion

  • What
  • Why
  • How
  1. assertEquals
  2. assertTrue / assertFalse
  3. assertNull / assertNotNull
  4. assertSame / assertNotSame
  5. assertArrayEquals

Exercise

使用上述五种断言各自实现一个例子

Matcher

Matcher

  • What
  • Why
  • How
  • assertThat
    
    
  • is
  • anyOf
  • both
  • not
  • startsWith
  • equalTo
  • lessThan
  • hasKey

Exercise

  1. 测试一个字符串是否包含字符“x"
  2. 用至少两种方法测试一个数字是否等于1024
  3. 测试一个数字是否为小于10的正数

Annotation

  1. @Test
  2. @Before
  3. @After
  4. @BeforeClass
  5. @AfterClass
  6. @Ignore

Exercise

  • 比较Before与BeforeClass,并设想它们各自的使用场景
Made with Slides.com