Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
JUnit
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Example of a JUnit test fixture== A JUnit [[test fixture#Software|test fixture]] is a Java object. Test methods must be annotated by the {{code|@Test}} [[Java annotation|annotation]]. If the situation requires it,<ref>{{cite web | url=http://c2.com/cgi/wiki?ExpensiveSetUpSmell | title=Expensive Setup Smell | publisher=C2 Wiki | author=Kent Beck | author-link=Kent Beck | access-date=2011-11-28}}</ref> it is also possible to define a method to execute before (or after) each (or all) of the test methods with the {{code|@BeforeEach}} (or {{code|@AfterEach}}) and {{code|@BeforeAll}} (or {{code|@AfterAll}}) annotations.<ref name="JUnit 5 User Guide: Writing Tests">{{cite web | url=https://junit.org/junit5/docs/current/user-guide/#writing-tests | title=Writing Tests | website=junit.org | access-date=2021-02-04}}</ref>{{sfn|Gulati|Sharma|2017|loc=Chapter Β§2 Understanding CoreJunit 5|p=37-40}} <syntaxhighlight lang=Java> import org.junit.jupiter.api.*; class FoobarTests { @BeforeAll static void setUpClass() throws Exception { // Code executed before the first test method } @BeforeEach void setUp() throws Exception { // Code executed before each test } @Test void oneThing() { // Code that tests one thing } @Test void anotherThing() { // Code that tests another thing } @Test void somethingElse() { // Code that tests something else } @AfterEach void tearDown() throws Exception { // Code executed after each test } @AfterAll static void tearDownClass() throws Exception { // Code executed after the last test method } } </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)