0% found this document useful (0 votes)
81 views

Junit

JUnit is an open source unit testing framework for Java programs. It allows developers to write and run repeatable tests that validate that sections of code are functioning as intended. Tests are organized into test cases that can be grouped into test suites. JUnit uses design patterns like command and composite to run tests and assert statements to validate results. Developers create test case classes that extend TestCase and define test methods along with optional setUp and tearDown methods.

Uploaded by

virusssp
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
81 views

Junit

JUnit is an open source unit testing framework for Java programs. It allows developers to write and run repeatable tests that validate that sections of code are functioning as intended. Tests are organized into test cases that can be grouped into test suites. JUnit uses design patterns like command and composite to run tests and assert statements to validate results. Developers create test case classes that extend TestCase and define test methods along with optional setUp and tearDown methods.

Uploaded by

virusssp
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

JUnit – a standard unit testing tool for Java programs

 Open source and documentation available at

http://www.junit.org

 [1,2] describe the Junit 3.x framework by using the following class diagram:

TestResult

<<Interface>>
Assert Test
*

TestCase
TestSuite
setUp()
runTest()
tearDown()

 The design of JUnit is based on the following patterns:


o Command (test cases are encapsulated and manipulated as objects)
o Composite (a TestSuite is a composite of TestCases)
o Template Method (tests are based on a template sequence of operations: each test
method is run between a call to setUp() and a call to tearDown())

 To create a test-case class you have to define a subclass of TestCase.


o Each test-case class may contain several test methods.
o Each test method is run in a fresh instance of the test-case class.
o The test-case class may override setUp() and tearDown().
 setUp() and tearDown() provide control over each test fixture (the set of
objects that are involved in a test).
o Assert provides (static) methods for checking the test values.
 You can write and execute collections of tests assembled in test suites.

 The new versions JUnit 4.x use annotations (require JDK 5 to run): @Before, @After, @Test
(for set up, tear down and test methods, respectively).

References

[1] Kent Beck. JUnit pocket guide. O’Reilly, 2004.


[2] JUnit A Cook’s Toor (available from http://www.junit.org)

You might also like