-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle
60 lines (51 loc) · 1.97 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
group 'io.behindthemath.mjolnir'
version '0.1.0'
apply plugin: 'java'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
testCompile 'org.mockito:mockito-core:1.10.19'
testCompile 'org.powermock:powermock-api-mockito:1.6.6'
testCompile 'org.powermock:powermock-module-junit4:1.6.6'
testCompile 'org.powermock:powermock-api-easymock:1.6.6'
}
jar {
manifest {
attributes(
'Main-Class': 'io.behindthemath.mjolnir.Main'
)
}
}
// Options for the Gradle task 'test'.
test {
beforeTest { TestDescriptor descriptor ->
// Log the test's class and method names.
logger.lifecycle("\n" + "Running test: " + descriptor.getClassName() + "." + descriptor.getName() + "()\n")
}
afterTest { TestDescriptor descriptor, TestResult result ->
// Log the test's results.
logger.lifecycle("\t" + "Test result: " + result.getResultType().toString())
if (result.getResultType() == TestResult.ResultType.SUCCESS) {
// If the test was successful, log the time it took to run the test.
String runTime = Long.toString(result.getEndTime() - result.getStartTime())
logger.lifecycle("\t" + "Test run time: " + runTime + " ms.")
} else if (result.getResultType() == TestResult.ResultType.FAILURE) {
// If the test failed, log the stack trace.
logger.lifecycle(parseStackTrace(result.getException()))
}
}
}
/**
* Parses the stack trace from a {@link Throwable} into a {@link String}.
* @param throwable
* @return A {@link String} with the stack trace of the {@link Throwable} passed in.
*/
static String parseStackTrace(Throwable throwable) {
final StringWriter stringWriter = new StringWriter()
final PrintWriter printWriter = new PrintWriter(stringWriter, true)
throwable.printStackTrace(printWriter)
return stringWriter.getBuffer().toString()
}