JUnit Testing: Lesson
Lesson 1 of 1
  1. 1
    JUnit testing operates in a Test Driven Development setting, or TDD, usually utilized specifically in “test-first” programming. Java programming as a whole is often synonymous with TDD due to t…
  2. 2
    JUnit testing takes place in a traditional Java class, just like the classes written for the application you want to test….
  3. 3
    @Test will be the bulk of any JUnit testing. Anything that needs to be “checked” and “verified” will likely occur within a method marked with the @Test annotation. A test method looks like this: @…
  4. 4
    “Red — Green — Refactor!” By the end of this lesson, this mantra should be playing in your mind whenever you think about testing your code. This mantra emphasizes the “test-first” approach to pro…
  5. 5
    A typical @Test method involves assertions. Assertions are found in the junit.org.Assert class library. Each “assert” is a way to perform a specific test in JUnit testing. Below are a couple …
  6. 6
    The @Before annotation can be used to accompany the @Test methods. Methods tagged with @Before will run before each test method and look like the following: @Before public void beforeEachTest() { …
  7. 7
    The @After annotation acts just like the @Before but will run after each test method. Particularly if this cleanup needs to occur after each test. @After public void afterEachTest() { // Clean…
  8. 8
    Getting the @Before, @Test, and @After methods all put together and tied up in a neat test class is the basis for JUnit testing. However, there’s one more step a programmer can take to apply one la…
  9. 9
    Congratulations! You completed the lesson on JUnit testing! 🙌 Key concepts covered in this lesson: - JUnit testing makes sure we have good test coverage across a program’s code and verifies everyt…

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory