A few weeks after my first post the other day, I made the next post. (Posted the other day: http://qiita.com/takumi_links/items/006777e9d5a29221dab0)
Although it was a book review of "a unit test at a programming site that can be done with zero experience", I did not personally try to move all the samples, so it was not well established ... So, I would like to dig a little deeper into the unit test in the sequel. think.
JUnit is a friend for Java engineers. Until now, I have always used "Eclipse" (Java development IDE) at the Java development site, but the testing framework that can be used with that Eclipse: JUnit. Although the version is out of date, there is a chapter called "Appendix" at the end of this book, which contains the setup instructions for the tools, plugins, and samples. In the current Eclipse, I think that Junit is often included as standard.
① JUnitRunner </ b> → ② Test class </ b> → ③ Test target class </ b> (Test execution class) (Created by JUnit function) (Created by the developer) ① JUnitRunner </ b> calls the ② test class </ b> test method, from which the test method calls the ③ test target class </ b> method, and its return value The mechanism of JUnit is to judge the success or failure of the test from. If you check it again ... I'm impressed that it's a convenient framework.
Annotation | Description |
---|---|
@Test | Test method. Called from JUnit |
@Before | Executed before the test method |
@After | Executed after the test method |
@BeforeClass | Runs once when you start running the test class |
@AfterClass | Run once when running and exiting the test class |
[Test class] </ b>
[Execution result] </ b>
Method | Description |
---|---|
assertTrue(Boolean condition) | Success if condition is true |
assertFalse(Boolean condition) | Success if condition is false |
assertEquals(Object expected,Object actual) | Success if the expected value and the actual value are equal |
assertSame(Object expected,Object actual) | Success if the expected value and the actual value are equal |
assertNull(Object object) | Success if the actual value is Null |
assertNotNull(Object object) | Success if the actual value is other than Null |
fail() | Force the test to fail |
When the evaluation method fails, an AssertionError is generated.
JUnit is also deep. Depending on the site, there was a unique testing framework, and I was away from building a pure JUnit, so I had to go back to the beginning and study again.