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. The functionality for those tests comes from JUnit classes, most commonly …
  3. 3
    @Test will be the bulk of any JUnit testing. Anything and everything that needs to be “checked” and “verified” will more often than not occur within a method marked with the @Test annotation. A te…
  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
    The bread and butter of a typical @Test method involve something called assertions. These assertions are found in the junit.org.Assert class library, and each “assert” is a way to perform a sp…
  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 very similarly to @Before but will run after each test method. @After public void afterEachTest() { // Cleanup } @After is majorly used for cleaning up variables a…
  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

Pro Logo