BAEL-2263 Using JUnit 5 with Gradle

This commit is contained in:
Johan Janssen 2018-10-11 21:40:30 +02:00
parent 90867eb6b4
commit 01819fe1ba
4 changed files with 74 additions and 1 deletions

View File

@ -0,0 +1,25 @@
plugins {
// Apply the java-library plugin to add support for Java Library
id 'java-library'
}
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.3.1'
// Only necessary for JUnit 3 and 4 tests
testCompileOnly 'junit:junit:4.12'
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine:5.3.1'
}
repositories {
jcenter()
}
test {
useJUnitPlatform {
includeTags 'fast'
excludeTags 'slow'
}
}

View File

@ -0,0 +1,12 @@
package com.example;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class CalculatorJUnit4Test {
@Test
public void testAdd() {
assertEquals(42, Integer.sum(19, 23));
}
}

View File

@ -0,0 +1,36 @@
package com.example;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;;
public class CalculatorJUnit5Test {
@Tag("fast")
@Test
public void testAdd() {
assertEquals(42, Integer.sum(19, 23));
}
@Tag("slow")
@Test
public void testAddMaxInteger() {
assertEquals(2147483646, Integer.sum(2147183646, 300000));
}
@Tag("fast")
@Test
public void testAddZero() {
assertEquals(21, Integer.sum(21, 0));
}
@Tag("fast")
@Test
public void testDivide() {
assertThrows(ArithmeticException.class, () -> {
Integer.divideUnsigned(42, 0);
});
}
}

View File

@ -5,6 +5,6 @@ include 'greeting-library'
include 'greeting-library-java'
include 'greeter'
include 'gradletaskdemo'
include 'junit5'
println 'This will be executed during the initialization phase.'