Learn Java Unit Testing with JUnit 5 in 20 Steps

Video description

JUnit is a unit testing framework for the Java programming language.

JUnit has been important in the development of test-driven development and is one of a family of unit testing frameworks which is collectively known as xUnit frameworks.

In this beginners tutorial on JUnit, you will learn how to

  • Create a new project for JUnit tests
  • Create, run and debug JUnit tests
  • Write good unit tests
  • Use assert methods
  • Use basic JUnit annotations - @Test, @Before, @After, @AfterClass, @BeforeClass, @Suite
  • Test performance and exceptions in unit tests
  • Write parameterized tests
  • Adhere to JUnit best practices
  • Use Eclipse to write and run JUnit tests

What You Will Learn

  • Write clean unit tests with the JUnit framework
  • Use JUnit annotations @Test, @Before, @After, @AfterClass, @BeforeClass, @Suite
  • Use JUnit assert methods
  • Write unit tests for exceptions and performance

Audience

Students new to unit testing and who want to understand unit testing. Students who want to understand the JUnit framework. Students with basic Java knowledge.

About The Author

In28Minutes Official: Ranga Karanam is a seasoned technologist and architect with over two decades of expertise in programming, design, and architecture. He founded in28Minutes with the goal of helping students master cutting-edge cloud-native technologies such as AWS, Azure, Google Cloud, Docker, and Kubernetes. With 15 years of experience in Java programming and design, Ranga has collaborated with top banking clients worldwide.

His passion for creating hands-on courses with real-world projects motivated him to develop the Step-By-Step series of courses that follow a problem-solution-based approach, with practical and real-world application examples.

Ranga and his team at in28Minutes specialize in Java and related frameworks such as Spring, Spring Boot, Spring MVC, Struts, and Hibernate. They are committed to equipping learners with the skills and knowledge necessary to succeed in today’s rapidly evolving technology landscape.

Table of contents

  1. Chapter 1 : JUnit 5
    1. Introduction
    2. Course Overview
    3. Step 01 - Introduction to Unit Testing - Test Pyramid
    4. Step 02 - First Junit Test - Red bar
    5. Step 03 - Absence of failure is success
    6. Step 04 - First Unit Test with JUnit - String length() method
    7. Step 05 - Writing JUnit Assertions - assertNull and assertTrue
    8. Step 06 - Writing Assertions for Arrays - assertArrayEquals
    9. Step 07 - Setting up data for every test - @BeforeEach, @AfterEach
    10. Step 08 - Setting up database connections - @BeforeAll, @AfterAll
    11. Step 09 - Tip - Testing Exceptions with Junit
    12. Step 10 - Tip - @DisplayName and test methods need not be public
    13. Step 11 - Basics of Parameterized tests
    14. Step 12 - Advanced Paramaterized Tests with Csv Source
    15. Step 13 - Tip - Giving a name to a Parameterized Test
    16. Step 14 - Tip - Repeat same test multiple times
    17. Step 15 - Tip - Unit Testing for Performance
    18. Step 16 - Tip - Disable Unit Tests
    19. Step 17 - Tip - Grouping Tests with @Nested
    20. Step 18 - Tip - JUnit 5 = Platform + Jupiter + Vintage
    21. Step 19 - Tip - JUnit 4 vs JUnit 5
    22. Step 20 - Tip - JUnit Best Practices
    23. Step 21 - Tip - JUnit Patterns - xunitpatterns
  2. Chapter 2 : JUnit 4
    1. Step 99 - JUnit 4 Section - First Version of the course
    2. Getting Ready for Hello World
    3. Your First JUnit Success - Green Bar
    4. Refactoring: Improving the Junit
    5. assertTrue and assertFalse
    6. @Before and @After
    7. @BeforeClass and @AfterClass
    8. Comparing Arrays - assertArrayEquals
    9. Unit Testing Exceptions
    10. Unit Testing for Performance
    11. Parameterized JUnit Tests
    12. Organizing Unit Tests into Suites
    13. How do you write good Unit Tests?
    14. Conclusion

Product information

  • Title: Learn Java Unit Testing with JUnit 5 in 20 Steps
  • Author(s): In28Minutes Official
  • Release date: May 2018
  • Publisher(s): Packt Publishing
  • ISBN: 9781789340648