Merge pull request #5429 from johanjanssen/master

BAEL-2263 Using JUnit 5 with Gradle
This commit is contained in:
Loredana Crusoveanu 2018-10-13 13:45:24 +03:00 committed by GitHub
commit a05b6b672a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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.'