At the time of static initialization of the class. system returns the value of System#nanoTime()
also called seed
, which is used for ordering the test cases. JUnit 5 logs the default seed at the info level.
package org.wesome.junit5;
public class AppleCalculator {
public int addApple(int appleBag1, int appleBag2) {
return appleBag1 + appleBag2;
}
}
package org.wesome.junit5;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import static org.junit.jupiter.api.Assertions.assertEquals;
@TestMethodOrder(MethodOrderer.Random.class)
class AppleCalculatorTest {
@Test
void addAppleTestCaseZ() {
AppleCalculator appleCalculator = new AppleCalculator();
assertEquals(2, appleCalculator.addApple(1, 1), "1 apple + 1 apple is 2 apple");
}
@Test
void addAppleTestCaseY() {
AppleCalculator appleCalculator = new AppleCalculator();
assertEquals(4, appleCalculator.addApple(2, 2), "2 apple + 2 apple is 4 apple");
}
@Test
void addAppleTestCaseX() {
AppleCalculator appleCalculator = new AppleCalculator();
assertEquals(6, appleCalculator.addApple(3, 3), "3 apple + 3 apple is 6 apple");
}
@Test
void addAppleTestCaseW() {
AppleCalculator appleCalculator = new AppleCalculator();
assertEquals(8, appleCalculator.addApple(4, 4), "4 apple + 4 apple is 8 apple");
}
@Test
void addAppleTestCaseV() {
AppleCalculator appleCalculator = new AppleCalculator();
assertEquals(10, appleCalculator.addApple(5, 5), "5 apple + 5 apple is 10 apple");
}
}
plugins {
id 'java'
id "io.freefair.lombok" version "6.2.0"
}
group = 'org.wesome'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = JavaVersion.VERSION_1_8
repositories {
mavenCentral()
}
dependencies {
testImplementation('org.junit.jupiter:junit-jupiter:5.6.2')
}
test {
useJUnitPlatform()
}