Junit 5

Appendix 1: Using JUnit 5 in Java Gradle Project.

Please paste the following content to the build.gradle file (in the root folder of the project) to replace the original one.

repositories {
    mavenCentral()
}

dependencies {
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.2.0'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.2.0'
    testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: '5.2.0'
}

test {
    useJUnitPlatform()
}
Appendix 2: Assertions in JUnit 5
// comparing two primitive typed values
final int expected = 2;
final int equivalent = 2;
assertEquals(expected, equivalent);

// comparing two object values
final String expected = "Hello";
final String equivalent = "Hello";
assertEquals(expected, equivalent);

// comparing if two objects are the same one
final Object expected = new Object();
final Object actual = expected;
assertSame(expected, actual);

// comparing elements in two arrays
final String[] expected = new String[] { "one", "two", "three" };
final String[] equivalent = new String[] { "one", "two", "three" };
assertArrayEquals(expected, equivalent);

// comparing elements in two iterables
final List expected = new ArrayList<>();
expected.add("one");
expected.add("two");
final List actual = Arrays.asList("one", "two");
assertIterableEquals(expected, actual);

// assert statements will throw an exception
assertThrows(NullPointerException.class, () -> ((String)null).length());

你可能感兴趣的:(Junit 5)