-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
89 lines (74 loc) · 2.64 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent
plugins {
id 'java'
id 'application'
id 'com.dorongold.task-tree' version '1.3.1'
}
repositories {
jcenter()
}
mainClassName = 'de.eekboom.dualtests.App'
dependencies {
testCompile 'junit:junit:4.12'
testCompile 'org.testng:testng:6.14.3'
}
// count failed tests, to print a message linking to the consolidated report if needed
project.ext.testFailureCount = 0
// Common configuration for both JUnit and TestNG tests
def testConfig = {
// Make the task show up in "verification" category
// in "gradle tasks" output and in IDEA's gradle tool window
group = 'verification'
// There is a separated task that creates a single report for both types of tests
reports.html.enabled = false
testLogging {
events TestLogEvent.FAILED // Show specific test failures in output
exceptionFormat = TestExceptionFormat.FULL // Output full failure details
}
// test listener that counts test failures
afterTest { TestDescriptor testDescriptor, TestResult testResult ->
if (testResult.resultType == TestResult.ResultType.FAILURE) {
++project.ext.testFailureCount
}
}
}
test {
configure testConfig
description = 'Runs the JUnit tests'
finalizedBy('testNg')
}
task testNg(type: Test) {
useTestNG()
configure testConfig
description = 'Runs the TestNG tests'
finalizedBy('testReport')
}
def testReportDir = file("$buildDir/reports/test-report")
task testReport(type: TestReport) {
destinationDir = testReportDir
// This does *not* work:
// reportOn test, testNg
// I guess that's because the testNg task was only executed as part of the "finalizedBy" mechanism
// (and not because of any "dependsOn"). So use "testResultDirs" instead:
testResultDirs = files("$buildDir/test-results/test/binary", "$buildDir/test-results/testNg/binary")
group = 'verification'
description = 'Generates a consolidated test report for both JUnit and TestNG tests'
}
gradle.buildFinished {
if (project.testFailureCount > 0) {
def failureText = (project.testFailureCount == 1
? 'was one test failure'
: "were ${project.testFailureCount} test failures"
)
def msg1 = "There " + failureText + " in ${project.name}."
def msg2 = "See report at file://${testReportDir}/index.html"
def len = Math.max(msg1.length(), msg2.length())
println ""
println "#" * len
println msg1
println msg2
println "#" * len
println ""
}
}