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
Unit testing
(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!
=== JUnit === Below is an example of a JUnit test suite. It focuses on the {{code|Adder}} class. <syntaxhighlight lang="java"> class Adder { public int add(int a, int b) { return a + b; } } </syntaxhighlight> The test suite uses [[Assertion (computing)|assert]] statements to verify the expected result of various input values to the {{code|sum}} method. <syntaxhighlight lang="java"> import static org.junit.Assert.assertEquals; import org.junit.Test; public class AdderUnitTest { @Test public void sumReturnsZeroForZeroInput() { Adder adder = new Adder(); assertEquals(0, adder.add(0, 0)); } @Test public void sumReturnsSumOfTwoPositiveNumbers() { Adder adder = new Adder(); assertEquals(3, adder.add(1, 2)); } @Test public void sumReturnsSumOfTwoNegativeNumbers() { Adder adder = new Adder(); assertEquals(-3, adder.add(-1, -2)); } @Test public void sumReturnsSumOfLargeNumbers() { Adder adder = new Adder(); assertEquals(2222, adder.add(1234, 988)); } } </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)