JUnit: Difference between revisions
No edit summary |
m Task 18 (cosmetic): eval 5 templates: hyphenate params (1×); |
||
Line 8: | Line 8: | ||
| developer = [[Kent Beck]], [[Erich Gamma]], David Saff, Kris Vasudevan |
| developer = [[Kent Beck]], [[Erich Gamma]], David Saff, Kris Vasudevan |
||
| latest release version = 5.6.3 |
| latest release version = 5.6.3 |
||
| latest release date = {{release date and age|2020|10|26}}<ref name="github">{{cite web|url=https://github.com/junit-team/junit5/releases|website=github.com|title=JUnit Releases | |
| latest release date = {{release date and age|2020|10|26}}<ref name="github">{{cite web|url=https://github.com/junit-team/junit5/releases|website=github.com|title=JUnit Releases |access-date=2021-01-18}}</ref> |
||
| operating system = [[Cross-platform]] |
| operating system = [[Cross-platform]] |
||
| programming language = [[Java programming language|Java]] |
| programming language = [[Java programming language|Java]] |
Revision as of 16:29, 25 January 2021
This article needs to be updated. The reason given is: this article focuses primarily on JUnit 4 and needs to be updated for JUnit 5.(June 2018) |
Developer(s) | Kent Beck, Erich Gamma, David Saff, Kris Vasudevan |
---|---|
Stable release | 5.6.3
/ October 26, 2020[1] |
Repository | |
Written in | Java |
Operating system | Cross-platform |
Type | Unit testing tool |
License | Eclipse Public License[2] (relicensed from CPL before) |
Website | junit |
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 that originated with SUnit.
JUnit is linked as a JAR at compile-time; the framework resides under package junit.framework
for JUnit 3.8 and earlier, and under package org.junit
for JUnit 4 and later.
A research survey performed in 2013 across 10,000 Java projects hosted on GitHub found that JUnit (in a tie with slf4j-api), was the most commonly included external library. Each library was used by 30.7% of projects.[3]
Example of JUnit test fixture
A JUnit test fixture is a Java object. With older versions of JUnit, fixtures had to inherit from junit.framework.TestCase
, but the new tests using JUnit 4 should not do this.[4] Test methods must be annotated by the @Test
annotation. If the situation requires it,[5] it is also possible to define a method to execute before (or after) each (or all) of the test methods with the @Before
(or @After
) and @BeforeClass
(or @AfterClass
) annotations.[4]
import org.junit.*;
public class FoobarTest {
@BeforeClass
public static void setUpClass() throws Exception {
// Code executed before the first test method
}
@Before
public void setUp() throws Exception {
// Code executed before each test
}
@Test
public void testOneThing() {
// Code that tests one thing
}
@Test
public void testAnotherThing() {
// Code that tests another thing
}
@Test
public void testSomethingElse() {
// Code that tests something else
}
@After
public void tearDown() throws Exception {
// Code executed after each test
}
@AfterClass
public static void tearDownClass() throws Exception {
// Code executed after the last test method
}
}
See also
- TestNG, another test framework for Java
- Mock object, a technique used during unit testing
- Mockito mocking extension to JUnit
- EvoSuite, a tool to automatically generate JUnit tests
- List of Java Frameworks
References
- ^ "JUnit Releases". github.com. Retrieved 2021-01-18.
- ^ "Relicense JUnit from CPL to EPL". Philippe Marschall. 18 May 2013. Retrieved 2013-09-20.
- ^ "We Analyzed 30,000 GitHub Projects – Here Are The Top 100 Libraries in Java, JS and Ruby".
- ^ a b Kent Beck; Erich Gamma. "JUnit Cookbook". junit.sourceforge.net. Retrieved 2011-05-21.
- ^ Kent Beck. "Expensive Setup Smell". C2 Wiki. Retrieved 2011-11-28.