TDD almost working, build.gradle cleaned up some
This commit is contained in:
parent
27fdeacf4c
commit
9c838f918b
35
build.gradle
35
build.gradle
@ -126,9 +126,6 @@ class Tags {
|
||||
}
|
||||
|
||||
ext {
|
||||
junit4Version = '4.12'
|
||||
junitVintageVersion = '4.12.0-M2'
|
||||
junitPlatformVersion = '1.0.0-M2'
|
||||
junitJupiterVersion = '5.0.0-M2'
|
||||
}
|
||||
|
||||
@ -148,26 +145,16 @@ subprojects {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// compile 'junit:junit:4.12'
|
||||
// Logging:
|
||||
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.+'
|
||||
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.+'
|
||||
// You can also use the JDK's built-in logging as the back end:
|
||||
// compile group: 'org.slf4j', name: 'slf4j-jdk14', version: '1.7.5'
|
||||
|
||||
// JUnit Jupiter API and TestEngine implementation
|
||||
/* testCompile("org.junit.jupiter:junit-jupiter-api:${junitJupiterVersion}")
|
||||
testRuntime("org.junit.jupiter:junit-jupiter-engine:${junitJupiterVersion}")
|
||||
|
||||
// If you also want to support JUnit 3 and JUnit 4 tests
|
||||
testCompile("junit:junit:${junit4Version}")
|
||||
testRuntime("org.junit.vintage:junit-vintage-engine:${junitVintageVersion}")*/
|
||||
compile "org.junit.jupiter:junit-jupiter-api:5.0.0-M2"
|
||||
testCompile "org.junit.jupiter:junit-jupiter-api:5.0.0-M2"
|
||||
testRuntime "org.junit.jupiter:junit-jupiter-engine:5.0.0-M2"
|
||||
/* testCompile "junit:junit:4.12"
|
||||
testRuntime "org.junit.vintage:junit-vintage-engine:4.12.0-M2"
|
||||
*//* compile "org.junit.jupiter:junit-jupiter-api:5.0.0-M2"
|
||||
compile "org.junit.vintage:junit-vintage-engine:4.12.0-M2"*/
|
||||
// JUnit testing:
|
||||
compile "org.junit.jupiter:junit-jupiter-api:${junitJupiterVersion}"
|
||||
testCompile "org.junit.jupiter:junit-jupiter-api:${junitJupiterVersion}"
|
||||
testRuntime "org.junit.jupiter:junit-jupiter-engine:${junitJupiterVersion}"
|
||||
}
|
||||
|
||||
junitPlatform {
|
||||
@ -191,11 +178,8 @@ subprojects {
|
||||
main {
|
||||
java {
|
||||
srcDir projectDir
|
||||
// exclude "*Test.java"
|
||||
exclude "*Tests.java"
|
||||
exclude "*JUnit.java"
|
||||
exclude "StringInverter*.java"
|
||||
// exclude "Queue.java"
|
||||
// Remove this when it's working:
|
||||
exclude "DynamicStringInverterTests.java"
|
||||
}
|
||||
resources {
|
||||
srcDir projectDir
|
||||
@ -234,7 +218,7 @@ subprojects {
|
||||
|
||||
// Exclude java sources that will not compile
|
||||
if (tags.compileTimeError) {
|
||||
println ">>> Excluding " + file.name
|
||||
// println ">>> Excluding " + file.name
|
||||
sourceSets.main.java.excludes.add(file.name)
|
||||
} else {
|
||||
JavaExec javaTask = null
|
||||
@ -362,9 +346,6 @@ configure(subprojects - project(':onjava')) {
|
||||
compile group: 'com.google.guava', name: 'guava', version: '19.0'
|
||||
compile "org.openjdk.jmh:jmh-core:${jmh.jmhVersion}"
|
||||
compile 'org.junit.platform:junit-platform-gradle-plugin:1.0.0-M2'
|
||||
|
||||
//compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.6.2'
|
||||
//compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.6.2'
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,6 @@
|
||||
// Simple use of JUnit to test CountedList.
|
||||
package verifying;
|
||||
import java.util.*;
|
||||
//import verifying.CountedList;
|
||||
import org.junit.jupiter.api.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@ -43,8 +42,8 @@ public class CountedListTest {
|
||||
// as it isn't annotated with @Test, it will not
|
||||
// be automatically executed by JUnit.
|
||||
private
|
||||
void compare(ArrayList<String> lst, String[] strs) {
|
||||
String[] array = (String[])lst.toArray();
|
||||
void compare(List<String> lst, String[] strs) {
|
||||
String[] array = lst.toArray(new String[0]);
|
||||
assertTrue(array.length == strs.length,
|
||||
"Arrays not the same length");
|
||||
for(int i = 0; i < array.length; i++)
|
||||
@ -72,11 +71,6 @@ public class CountedListTest {
|
||||
compare(list, new String[] { "0", "1", "2",
|
||||
"An", "African", "Swallow" });
|
||||
}
|
||||
/* public static void main(String[] args) {
|
||||
// Invoke JUnit on the class:
|
||||
org.junit.runner.JUnitCore.runClasses(
|
||||
SimpleJUnit.class);
|
||||
} */
|
||||
}
|
||||
/* Output:
|
||||
CountedList #0
|
||||
|
80
verifying/DynamicStringInverterTests.java
Normal file
80
verifying/DynamicStringInverterTests.java
Normal file
@ -0,0 +1,80 @@
|
||||
// verifying/DynamicStringInverterTests.java
|
||||
// (c)2016 MindView LLC: see Copyright.txt
|
||||
// We make no guarantees that this code is fit for any purpose.
|
||||
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
|
||||
package verifying;
|
||||
import java.util.*;
|
||||
import java.util.function.*;
|
||||
import java.util.stream.*;
|
||||
import org.junit.jupiter.api.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.junit.jupiter.api.DynamicTest.*;
|
||||
|
||||
class DynamicStringInverterTests {
|
||||
Stream<DynamicTest>
|
||||
multiple_version_test(Consumer<StringInverter> test) {
|
||||
List<StringInverter> versions = Arrays.asList(
|
||||
new StringInverter1(), new StringInverter2(),
|
||||
new StringInverter3(), new StringInverter4());
|
||||
return DynamicTest.stream(versions.iterator(),
|
||||
(version) -> version.getClass().getSimpleName(),
|
||||
test
|
||||
);
|
||||
}
|
||||
|
||||
@TestFactory
|
||||
Stream<DynamicTest> basicInversion_Succeed() {
|
||||
return multiple_version_test( (version) -> {
|
||||
String in = "Exit, Pursued by a Bear.";
|
||||
String out = "eXIT, pURSUED BY A bEAR.";
|
||||
assertEquals(version.invert(in), out);
|
||||
});
|
||||
}
|
||||
|
||||
@TestFactory
|
||||
Stream<DynamicTest> basicInversion_Fail() {
|
||||
return multiple_version_test( (version) -> {
|
||||
expectThrows(RuntimeException.class, () -> {
|
||||
assertEquals(version.invert("X"), "X");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@TestFactory
|
||||
Stream<DynamicTest> allowedCharacters_Fail() {
|
||||
return multiple_version_test( (version) -> {
|
||||
expectThrows(RuntimeException.class, () -> {
|
||||
version.invert(";-_()*&^%$#@!~`");
|
||||
version.invert("0123456789");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@TestFactory
|
||||
Stream<DynamicTest> allowedCharacters_Succeed() {
|
||||
return multiple_version_test( (version) -> {
|
||||
version.invert("abcdefghijklmnopqrstuvwxyz ,.");
|
||||
version.invert("ABCDEFGHIJKLMNOPQRSTUVWXYZ ,.");
|
||||
});
|
||||
}
|
||||
|
||||
@TestFactory
|
||||
Stream<DynamicTest> lengthLessThan26_Fail() {
|
||||
return multiple_version_test( (version) -> {
|
||||
String str = "xxxxxxxxxxxxxxxxxxxxxxxxxx";
|
||||
assertTrue(str.length() > 25);
|
||||
expectThrows(RuntimeException.class, () -> {
|
||||
version.invert(str);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@TestFactory
|
||||
Stream<DynamicTest> lengthLessThan26_Succeed() {
|
||||
return multiple_version_test( (version) -> {
|
||||
String str = "xxxxxxxxxxxxxxxxxxxxxxxxx";
|
||||
assertTrue(str.length() < 26);
|
||||
version.invert(str);
|
||||
});
|
||||
}
|
||||
}
|
@ -7,8 +7,9 @@ import org.junit.jupiter.api.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class FirstJUnit5Tests {
|
||||
@Test
|
||||
void myFirstTest() {
|
||||
assertEquals(2, 1 + 1);
|
||||
}
|
||||
@Test
|
||||
void myFirstTest() {
|
||||
System.out.println("FirstJUnit5Tests");
|
||||
assertEquals(2, 1 + 1);
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
// (c)2016 MindView LLC: see Copyright.txt
|
||||
// We make no guarantees that this code is fit for any purpose.
|
||||
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
|
||||
package verifying;
|
||||
|
||||
interface StringInverter {
|
||||
public String invert(String str);
|
||||
|
@ -2,7 +2,7 @@
|
||||
// (c)2016 MindView LLC: see Copyright.txt
|
||||
// We make no guarantees that this code is fit for any purpose.
|
||||
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
|
||||
// {java StringInverterTest StringInverter1}
|
||||
package verifying;
|
||||
|
||||
public class StringInverter1 implements StringInverter {
|
||||
public String invert(String str) { return ""; }
|
||||
|
@ -2,7 +2,7 @@
|
||||
// (c)2016 MindView LLC: see Copyright.txt
|
||||
// We make no guarantees that this code is fit for any purpose.
|
||||
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
|
||||
// {java StringInverterTest StringInverter2}
|
||||
package verifying;
|
||||
import static java.lang.Character.*;
|
||||
|
||||
public class StringInverter2 implements StringInverter {
|
||||
|
@ -2,7 +2,7 @@
|
||||
// (c)2016 MindView LLC: see Copyright.txt
|
||||
// We make no guarantees that this code is fit for any purpose.
|
||||
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
|
||||
// {java StringInverterTest StringInverter3}
|
||||
package verifying;
|
||||
import static java.lang.Character.*;
|
||||
|
||||
public class StringInverter3 implements StringInverter {
|
||||
|
@ -2,7 +2,7 @@
|
||||
// (c)2016 MindView LLC: see Copyright.txt
|
||||
// We make no guarantees that this code is fit for any purpose.
|
||||
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
|
||||
// {java StringInverterTest StringInverter4}
|
||||
package verifying;
|
||||
import static java.lang.Character.*;
|
||||
|
||||
public class StringInverter4 implements StringInverter {
|
||||
|
@ -1,69 +0,0 @@
|
||||
// verifying/StringInverterTest.java
|
||||
// (c)2016 MindView LLC: see Copyright.txt
|
||||
// We make no guarantees that this code is fit for any purpose.
|
||||
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
|
||||
// {ValidateByHand} // Don't run by itself
|
||||
import java.util.*;
|
||||
import org.junit.jupiter.api.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
// import org.junit.platform.runner.JUnitPlatform;
|
||||
|
||||
public class StringInverterTest {
|
||||
static StringInverter inverter;
|
||||
@Test
|
||||
public final void basicInversion_Succeed() {
|
||||
String in = "Exit, Pursued by a Bear.";
|
||||
String out = "eXIT, pURSUED BY A bEAR.";
|
||||
assertEquals(inverter.invert(in), out);
|
||||
}
|
||||
@Test
|
||||
public final void basicInversion_Fail() {
|
||||
expectThrows(RuntimeException.class, () -> {
|
||||
assertEquals(inverter.invert("X"), "X");
|
||||
});
|
||||
}
|
||||
@Test
|
||||
public final void allowedCharacters_Fail() {
|
||||
expectThrows(RuntimeException.class, () -> {
|
||||
inverter.invert(";-_()*&^%$#@!~`");
|
||||
inverter.invert("0123456789");
|
||||
});
|
||||
}
|
||||
@Test
|
||||
public final void allowedCharacters_Succeed() {
|
||||
inverter.invert("abcdefghijklmnopqrstuvwxyz ,.");
|
||||
inverter.invert("ABCDEFGHIJKLMNOPQRSTUVWXYZ ,.");
|
||||
}
|
||||
@Test
|
||||
public final void lengthLessThan26_Fail() {
|
||||
String str = "xxxxxxxxxxxxxxxxxxxxxxxxxx";
|
||||
assertTrue(str.length() > 25);
|
||||
expectThrows(RuntimeException.class, () -> {
|
||||
inverter.invert(str);
|
||||
});
|
||||
}
|
||||
@Test
|
||||
public final void lengthLessThan26_Succeed() {
|
||||
String str = "xxxxxxxxxxxxxxxxxxxxxxxxx";
|
||||
assertTrue(str.length() < 26);
|
||||
inverter.invert(str);
|
||||
}
|
||||
/*
|
||||
public static void main(String[] args) throws Exception{
|
||||
assertEquals(args.length, 1);
|
||||
inverter = (StringInverter)
|
||||
Class.forName(args[0]).newInstance();
|
||||
Result result = org.junit.runner.JUnitCore.runClasses(
|
||||
StringInverterTest.class);
|
||||
List<Failure> failures = result.getFailures();
|
||||
System.out.printf("%s has %d FAILURES:\n",
|
||||
args[0], failures.size());
|
||||
int count = 1;
|
||||
for(Failure f : failures) {
|
||||
System.out.printf("Failure %d:\n", count++);
|
||||
System.out.println(f.getDescription());
|
||||
System.out.println(f.getMessage());
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user