Skip to content

Commit 07512f2

Browse files
author
Bruce Eckel
committed
build sort of working for tests, testable files in packages
1 parent f52ebca commit 07512f2

File tree

4 files changed

+74
-7
lines changed

4 files changed

+74
-7
lines changed

build.gradle

Lines changed: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ buildscript {
44
jcenter()
55
mavenCentral()
66
}
7+
dependencies {
8+
classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.0-M2'
9+
}
710
}
811

912
plugins {
10-
// id 'com.gradle.build-scan' version '1.0' // Should be first in list
1113
id 'com.github.johnrengelman.shadow' version '1.2.3'
1214
id 'me.champeau.gradle.jmh' version '0.3.1'
1315
}
@@ -123,10 +125,16 @@ class Tags {
123125
}
124126
}
125127

128+
ext.junit4Version = '4.12'
129+
ext.junitVintageVersion = '4.12.0-M2'
130+
ext.junitPlatformVersion = '1.0.0-M2'
131+
ext.junitJupiterVersion = '5.0.0-M2'
132+
126133
subprojects {
127134
apply plugin: 'com.github.johnrengelman.shadow'
128135
apply plugin: 'me.champeau.gradle.jmh'
129136
apply plugin: 'java'
137+
apply plugin: 'org.junit.platform.gradle.plugin'
130138

131139
sourceCompatibility = '1.8'
132140
targetCompatibility = '1.8'
@@ -138,26 +146,72 @@ subprojects {
138146
}
139147

140148
dependencies {
141-
compile 'junit:junit:4.12'
149+
//compile 'junit:junit:4.12'
142150
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.+'
143151
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.+'
144152
// You can also use the JDK's built-in logging as the back end:
145153
// compile group: 'org.slf4j', name: 'slf4j-jdk14', version: '1.7.5'
154+
155+
// JUnit Jupiter API and TestEngine implementation
156+
/* testCompile("org.junit.jupiter:junit-jupiter-api:${junitJupiterVersion}")
157+
testRuntime("org.junit.jupiter:junit-jupiter-engine:${junitJupiterVersion}")
158+
159+
// If you also want to support JUnit 3 and JUnit 4 tests
160+
testCompile("junit:junit:${junit4Version}")
161+
testRuntime("org.junit.vintage:junit-vintage-engine:${junitVintageVersion}")*/
162+
testCompile "org.junit.jupiter:junit-jupiter-api:5.0.0-M2"
163+
testRuntime "org.junit.jupiter:junit-jupiter-engine:5.0.0-M2"
164+
testCompile "junit:junit:4.12"
165+
testRuntime "org.junit.vintage:junit-vintage-engine:4.12.0-M2"
166+
}
167+
168+
junitPlatform {
169+
// platformVersion '1.0.0-SNAPSHOT'
170+
//engines {
171+
// include 'junit-jupiter', 'junit-vintage'
172+
// exclude 'custom-engine'
173+
//}
174+
/* tags {
175+
// include 'fast'
176+
exclude 'slow'
177+
}*/
178+
//includeClassNamePattern '.*Test'
179+
includeClassNamePattern '.*'
180+
// enableStandardTestTask true
181+
// reportsDir "build/test-results/junit-platform" // this is the default
182+
//logManager 'org.apache.logging.log4j.jul.LogManager'
146183
}
147184

148185
sourceSets {
149186
main {
150187
java {
151188
srcDir projectDir
189+
exclude "*Test.java"
190+
exclude "*Tests.java"
191+
exclude "*JUnit.java"
192+
exclude "StringInverter*.java"
193+
exclude "Queue.java"
152194
}
195+
/* filter {
196+
}*/
153197
}
154198
jmh {
155199
java {
156200
srcDir projectDir
157201
}
158202
}
203+
test {
204+
java {
205+
srcDir projectDir
206+
}
207+
}
159208
}
160209

210+
/*test {
211+
testClassesDir = sourceSets.main.output.classesDir
212+
classpath = sourceSets.main.runtimeClasspath
213+
}*/
214+
161215
jmh {
162216
jmhVersion = '1.13'
163217
duplicateClassesStrategy = 'warn'
@@ -299,6 +353,8 @@ configure(subprojects - project(':onjava')) {
299353
compile project(':onjava')
300354
compile group: 'com.google.guava', name: 'guava', version: '19.0'
301355
compile "org.openjdk.jmh:jmh-core:${jmh.jmhVersion}"
356+
compile 'org.junit.platform:junit-platform-gradle-plugin:1.0.0-M2'
357+
302358
//compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.6.2'
303359
//compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.6.2'
304360
}
@@ -311,8 +367,3 @@ task verify(type:Exec) {
311367
println("execute 'gradlew run' first")
312368
}
313369
}
314-
315-
/*buildScan {
316-
licenseAgreementUrl = 'https://gradle.com/terms-of-service'
317-
licenseAgree = 'yes'
318-
}*/

verifying/FirstJUnit5Tests.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// verifying/FirstJUnit5Tests.java
2+
// (c)2016 MindView LLC: see Copyright.txt
3+
// We make no guarantees that this code is fit for any purpose.
4+
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
5+
package verifying;
6+
import static org.junit.jupiter.api.Assertions.assertEquals;
7+
import org.junit.jupiter.api.Test;
8+
9+
class FirstJUnit5Tests {
10+
@Test
11+
void myFirstTest() {
12+
assertEquals(2, 1 + 1);
13+
}
14+
}

verifying/Queue.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
55
// Demonstration of Design by Contract (DbC)
66
// combined with white-box unit testing
7+
package verifying;
78
import java.util.*;
89
import org.junit.Test;
910
import static org.junit.Assert.assertEquals;

verifying/SimpleJUnit.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// We make no guarantees that this code is fit for any purpose.
44
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
55
// Simple use of JUnit to test ArrayList
6+
package verifying;
67
import java.util.*;
78
import org.junit.*;
89
import static org.junit.Assert.*;

0 commit comments

Comments
 (0)