From the course: Programming Foundations: Test-Driven Development

xUnit and JUnit - Java Tutorial

From the course: Programming Foundations: Test-Driven Development

Start my 1-month free trial

xUnit and JUnit

- [Instructor] Most popular unit testing frameworks for various programming languages are modeled on what is called xUnit Framework. The core of xUnit was designed by Ken Beck and Eric Gamma for small talk named as sUnit. This was later ported for Java and named as JUnit. JUnit's popularity and wide acceptance led other languages to follow suit and create their own unit testing frameworks based on the xUnit architecture. A common xUnit framework makes it easy for developers to learn the basic TTD techniques and then apply them across different languages. So, if you have learned one xUnit testing framework, say JUnit, then it is very easy for you to apply the same knowledge to the testing frameworks for other languages. These xUnit frameworks have a core architecture and some of its key components are test case, test suit, test runner, test fixture, and test result. These terms have a common meaning across all xUnit platforms. While you will learn about these terms later in this course, it is helpful to know at this point that these concepts are transferable across whichever xUnit tools you plan to use. As the world of xUnit evolved, so did the JUnit framework. Junit 3 was based on Java 5 and in spite of being at the forefront of xUnit evolution it had its limitations. Developers had to take care of basic considerations. For example, to write a test case they had to extend the library class test case and name their test methods starting with the word test. Then came Junit 4 that was developed for JUnit 8, offering the use of annotations and thereby removing many of JUnit 3 restrictions. It introduced new features such as rules and the flexibility to change the test runner. While JUnit 4 was very successful and widely adopted over 10 years, it still lacked the flexibility and extensibility that the developers desired. For this reason, Junit 5 was released in 2017 with its core architecture redesigned to be completely modular, extensible to seamlessly integrate with third-party tools. From a developer point of view JUnit 5 gives a much richer set of testing functionalities. In Java 5, the core has three modules; platform, vintage, and Jupiter. The test cases that you write interact with either the vintage module or the Jupiter module. Vintage supports legacy code in JUnit 3 and 4. And Jupiter offers the new programing and extension modules of JUnit 5. The platform has the engine to run these two modules. The platform also has the launching platform to interface with IDEs such as Intelligent Eclipse and build frameworks such as Maven and (mumbles) so that you can run your unit test cases from within these tools.

Contents