-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
AbstractTestTask.java
665 lines (592 loc) · 25.7 KB
/
AbstractTestTask.java
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
/*
* Copyright 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.gradle.api.tasks.testing;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
import groovy.lang.Closure;
import org.gradle.api.Action;
import org.gradle.api.file.DeleteSpec;
import org.gradle.api.file.DirectoryProperty;
import org.gradle.api.file.FileSystemOperations;
import org.gradle.api.internal.ConventionTask;
import org.gradle.api.internal.tasks.testing.DefaultTestTaskReports;
import org.gradle.api.internal.tasks.testing.FailFastTestListenerInternal;
import org.gradle.api.internal.tasks.testing.TestExecuter;
import org.gradle.api.internal.tasks.testing.TestExecutionSpec;
import org.gradle.api.internal.tasks.testing.TestResultProcessor;
import org.gradle.api.internal.tasks.testing.filter.DefaultTestFilter;
import org.gradle.api.internal.tasks.testing.junit.result.Binary2JUnitXmlReportGenerator;
import org.gradle.api.internal.tasks.testing.junit.result.InMemoryTestResultsProvider;
import org.gradle.api.internal.tasks.testing.junit.result.JUnitXmlResultOptions;
import org.gradle.api.internal.tasks.testing.junit.result.TestClassResult;
import org.gradle.api.internal.tasks.testing.junit.result.TestOutputStore;
import org.gradle.api.internal.tasks.testing.junit.result.TestReportDataCollector;
import org.gradle.api.internal.tasks.testing.junit.result.TestResultSerializer;
import org.gradle.api.internal.tasks.testing.junit.result.TestResultsProvider;
import org.gradle.api.internal.tasks.testing.logging.DefaultTestLoggingContainer;
import org.gradle.api.internal.tasks.testing.logging.FullExceptionFormatter;
import org.gradle.api.internal.tasks.testing.logging.ShortExceptionFormatter;
import org.gradle.api.internal.tasks.testing.logging.TestCountLogger;
import org.gradle.api.internal.tasks.testing.logging.TestEventLogger;
import org.gradle.api.internal.tasks.testing.logging.TestExceptionFormatter;
import org.gradle.api.internal.tasks.testing.logging.TestWorkerProgressListener;
import org.gradle.api.internal.tasks.testing.report.DefaultTestReport;
import org.gradle.api.internal.tasks.testing.report.TestReporter;
import org.gradle.api.internal.tasks.testing.results.StateTrackingTestResultProcessor;
import org.gradle.api.internal.tasks.testing.results.TestListenerAdapter;
import org.gradle.api.internal.tasks.testing.results.TestListenerInternal;
import org.gradle.api.logging.LogLevel;
import org.gradle.api.model.ReplacedBy;
import org.gradle.api.reporting.DirectoryReport;
import org.gradle.api.reporting.Reporting;
import org.gradle.api.tasks.Internal;
import org.gradle.api.tasks.Nested;
import org.gradle.api.tasks.OutputDirectory;
import org.gradle.api.tasks.TaskAction;
import org.gradle.api.tasks.VerificationException;
import org.gradle.api.tasks.VerificationTask;
import org.gradle.api.tasks.options.Option;
import org.gradle.api.tasks.testing.logging.TestLogging;
import org.gradle.api.tasks.testing.logging.TestLoggingContainer;
import org.gradle.internal.Cast;
import org.gradle.internal.concurrent.CompositeStoppable;
import org.gradle.internal.deprecation.DeprecationLogger;
import org.gradle.internal.event.ListenerBroadcast;
import org.gradle.internal.event.ListenerManager;
import org.gradle.internal.logging.ConsoleRenderer;
import org.gradle.internal.logging.progress.ProgressLogger;
import org.gradle.internal.logging.progress.ProgressLoggerFactory;
import org.gradle.internal.logging.text.StyledTextOutputFactory;
import org.gradle.internal.nativeintegration.network.HostnameLookup;
import org.gradle.internal.operations.BuildOperationExecutor;
import org.gradle.internal.reflect.Instantiator;
import org.gradle.listener.ClosureBackedMethodInvocationDispatch;
import org.gradle.util.internal.ClosureBackedAction;
import org.gradle.util.internal.ConfigureUtil;
import org.gradle.work.DisableCachingByDefault;
import javax.inject.Inject;
import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Abstract class for all test tasks.
*
* <ul>
* <li>Support for test listeners</li>
* <li>Support for reporting</li>
* <li>Support for report linking in the console output</li>
* </ul>
*
* <p><b>Note:</b> This abstract class is not intended for implementation by build script or plugin authors.
*
* @since 4.4
*/
@DisableCachingByDefault(because = "Abstract super-class, not to be instantiated directly")
public abstract class AbstractTestTask extends ConventionTask implements VerificationTask, Reporting<TestTaskReports> {
private final DefaultTestFilter filter;
private final TestTaskReports reports;
private final ListenerBroadcast<TestListener> testListenerBroadcaster;
private final ListenerBroadcast<TestOutputListener> testOutputListenerBroadcaster;
private final ListenerBroadcast<TestListenerInternal> testListenerInternalBroadcaster;
private final TestLoggingContainer testLogging;
private final DirectoryProperty binaryResultsDirectory;
private TestReporter testReporter;
private boolean ignoreFailures;
private boolean failFast;
public AbstractTestTask() {
Instantiator instantiator = getInstantiator();
testLogging = instantiator.newInstance(DefaultTestLoggingContainer.class, instantiator);
ListenerManager listenerManager = getListenerManager();
testListenerInternalBroadcaster = listenerManager.createAnonymousBroadcaster(TestListenerInternal.class);
testOutputListenerBroadcaster = listenerManager.createAnonymousBroadcaster(TestOutputListener.class);
testListenerBroadcaster = listenerManager.createAnonymousBroadcaster(TestListener.class);
binaryResultsDirectory = getProject().getObjects().directoryProperty();
reports = getProject().getObjects().newInstance(DefaultTestTaskReports.class, this);
reports.getJunitXml().getRequired().set(true);
reports.getHtml().getRequired().set(true);
filter = instantiator.newInstance(DefaultTestFilter.class);
}
@Inject
protected ProgressLoggerFactory getProgressLoggerFactory() {
throw new UnsupportedOperationException();
}
@Inject
protected StyledTextOutputFactory getTextOutputFactory() {
throw new UnsupportedOperationException();
}
@Inject
protected HostnameLookup getHostnameLookup() {
throw new UnsupportedOperationException();
}
@Inject
protected BuildOperationExecutor getBuildOperationExecutor() {
throw new UnsupportedOperationException();
}
@Inject
protected Instantiator getInstantiator() {
throw new UnsupportedOperationException();
}
@Inject
protected ListenerManager getListenerManager() {
throw new UnsupportedOperationException();
}
@Inject
protected FileSystemOperations getFileSystemOperations() {
throw new UnsupportedOperationException();
}
/**
* Creates test executer. For internal use only.
*
* @since 4.4
*/
protected abstract TestExecuter<? extends TestExecutionSpec> createTestExecuter();
/**
* Creates test execution specification. For internal use only.
*
* @since 4.4
*/
protected abstract TestExecutionSpec createTestExecutionSpec();
@Internal
@VisibleForTesting
ListenerBroadcast<TestOutputListener> getTestOutputListenerBroadcaster() {
return testOutputListenerBroadcaster;
}
@Internal
@VisibleForTesting
ListenerBroadcast<TestListenerInternal> getTestListenerInternalBroadcaster() {
return testListenerInternalBroadcaster;
}
@VisibleForTesting
void setTestReporter(TestReporter testReporter) {
this.testReporter = testReporter;
}
// only way I know of to determine current log level
private LogLevel determineCurrentLogLevel() {
for (LogLevel level : LogLevel.values()) {
if (getLogger().isEnabled(level)) {
return level;
}
}
throw new AssertionError("could not determine current log level");
}
/**
* Returns the root folder for the test results in internal binary format.
*
* @return the test result directory, containing the test results in binary format.
*
* @deprecated Use {@link #getBinaryResultsDirectory()} instead. This method will be removed in Gradle 8.0.
*/
@ReplacedBy("binaryResultsDirectory")
@Deprecated
public File getBinResultsDir() {
DeprecationLogger.deprecateProperty(AbstractTestTask.class, "binResultsDir").replaceWith("binaryResultsDirectory")
.willBeRemovedInGradle8()
.withDslReference()
.nagUser();
return binaryResultsDirectory.getAsFile().getOrNull();
}
/**
* Sets the root folder for the test results in internal binary format.
*
* @param binResultsDir The root folder
*
* @deprecated Use {@link #getBinaryResultsDirectory()}.set() instead. This method will be removed in Gradle 8.0.
*/
@Deprecated
public void setBinResultsDir(File binResultsDir) {
DeprecationLogger.deprecateProperty(AbstractTestTask.class, "binResultsDir").replaceWith("binaryResultsDirectory")
.willBeRemovedInGradle8()
.withDslReference()
.nagUser();
this.binaryResultsDirectory.set(binResultsDir);
}
/**
* Returns the root directory property for the test results in internal binary format.
*
* @since 4.4
*/
@OutputDirectory
public DirectoryProperty getBinaryResultsDirectory() {
return binaryResultsDirectory;
}
/**
* Registers a test listener with this task. Consider also the following handy methods for quicker hooking into test execution: {@link #beforeTest(groovy.lang.Closure)}, {@link
* #afterTest(groovy.lang.Closure)}, {@link #beforeSuite(groovy.lang.Closure)}, {@link #afterSuite(groovy.lang.Closure)} <p> This listener will NOT be notified of tests executed by other tasks. To
* get that behavior, use {@link org.gradle.api.invocation.Gradle#addListener(Object)}.
*
* @param listener The listener to add.
*/
public void addTestListener(TestListener listener) {
testListenerBroadcaster.add(listener);
}
/**
* Registers a output listener with this task. Quicker way of hooking into output events is using the {@link #onOutput(groovy.lang.Closure)} method.
*
* @param listener The listener to add.
*/
public void addTestOutputListener(TestOutputListener listener) {
testOutputListenerBroadcaster.add(listener);
}
/**
* Unregisters a test listener with this task. This method will only remove listeners that were added by calling {@link #addTestListener(TestListener)} on this task. If the listener was
* registered with Gradle using {@link org.gradle.api.invocation.Gradle#addListener(Object)} this method will not do anything. Instead, use {@link
* org.gradle.api.invocation.Gradle#removeListener(Object)}.
*
* @param listener The listener to remove.
*/
public void removeTestListener(TestListener listener) {
testListenerBroadcaster.remove(listener);
}
/**
* Unregisters a test output listener with this task. This method will only remove listeners that were added by calling {@link #addTestOutputListener(TestOutputListener)} on this task. If the
* listener was registered with Gradle using {@link org.gradle.api.invocation.Gradle#addListener(Object)} this method will not do anything. Instead, use {@link
* org.gradle.api.invocation.Gradle#removeListener(Object)}.
*
* @param listener The listener to remove.
*/
public void removeTestOutputListener(TestOutputListener listener) {
testOutputListenerBroadcaster.remove(listener);
}
/**
* {@inheritDoc}
*/
@Internal
@Override
public boolean getIgnoreFailures() {
return ignoreFailures;
}
/**
* {@inheritDoc}
*/
@Override
public void setIgnoreFailures(boolean ignoreFailures) {
this.ignoreFailures = ignoreFailures;
}
private TestExceptionFormatter getExceptionFormatter(TestLogging testLogging) {
switch (testLogging.getExceptionFormat()) {
case SHORT:
return new ShortExceptionFormatter(testLogging);
case FULL:
return new FullExceptionFormatter(testLogging);
default:
throw new AssertionError();
}
}
/**
* Adds a closure to be notified when output from the test received. A {@link TestDescriptor} and {@link TestOutputEvent} instance are
* passed to the closure as a parameter.
*
* <pre class='autoTested'>
* apply plugin: 'java'
*
* test {
* onOutput { descriptor, event ->
* if (event.destination == TestOutputEvent.Destination.StdErr) {
* logger.error("Test: " + descriptor + ", error: " + event.message)
* }
* }
* }
* </pre>
*
* @param closure The closure to call.
*/
public void onOutput(Closure closure) {
testOutputListenerBroadcaster.add(new ClosureBackedMethodInvocationDispatch("onOutput", closure));
}
/**
* <p>Adds a closure to be notified before a test suite is executed. A {@link TestDescriptor} instance is passed to the closure as a parameter.</p>
*
* <p>This method is also called before any test suites are executed. The provided descriptor will have a null parent suite.</p>
*
* @param closure The closure to call.
*/
public void beforeSuite(Closure closure) {
testListenerBroadcaster.add(new ClosureBackedMethodInvocationDispatch("beforeSuite", closure));
}
/**
* <p>Adds a closure to be notified after a test suite has executed. A {@link TestDescriptor} and {@link TestResult} instance are passed to the closure as a
* parameter.</p>
*
* <p>This method is also called after all test suites are executed. The provided descriptor will have a null parent suite.</p>
*
* @param closure The closure to call.
*/
public void afterSuite(Closure closure) {
testListenerBroadcaster.add(new ClosureBackedMethodInvocationDispatch("afterSuite", closure));
}
/**
* Adds a closure to be notified before a test is executed. A {@link TestDescriptor} instance is passed to the closure as a parameter.
*
* @param closure The closure to call.
*/
public void beforeTest(Closure closure) {
testListenerBroadcaster.add(new ClosureBackedMethodInvocationDispatch("beforeTest", closure));
}
/**
* Adds a closure to be notified after a test has executed. A {@link TestDescriptor} and {@link TestResult} instance are passed to the closure as a parameter.
*
* @param closure The closure to call.
*/
public void afterTest(Closure closure) {
testListenerBroadcaster.add(new ClosureBackedMethodInvocationDispatch("afterTest", closure));
}
/**
* Allows to set options related to which test events are logged to the console, and on which detail level. For example, to show more information about exceptions use:
*
* <pre class='autoTested'>
* apply plugin: 'java'
*
* test.testLogging {
* exceptionFormat "full"
* }
* </pre>
*
* For further information see {@link TestLoggingContainer}.
*
* @return this
*/
@Internal
// TODO:LPTR Should be @Nested with @Console inside
public TestLoggingContainer getTestLogging() {
return testLogging;
}
/**
* Allows configuring the logging of the test execution, for example log eagerly the standard output, etc.
*
* <pre class='autoTested'>
* apply plugin: 'java'
*
* // makes the standard streams (err and out) visible at console when running tests
* test.testLogging {
* showStandardStreams = true
* }
* </pre>
*
* @param closure configure closure
*/
public void testLogging(Closure closure) {
ConfigureUtil.configure(closure, testLogging);
}
/**
* Allows configuring the logging of the test execution, for example log eagerly the standard output, etc.
*
* <pre class='autoTested'>
* apply plugin: 'java'
*
* // makes the standard streams (err and out) visible at console when running tests
* test.testLogging {
* showStandardStreams = true
* }
* </pre>
*
* @param action configure action
* @since 3.5
*/
public void testLogging(Action<? super TestLoggingContainer> action) {
action.execute(testLogging);
}
@TaskAction
public void executeTests() {
LogLevel currentLevel = determineCurrentLogLevel();
TestLogging levelLogging = getTestLogging().get(currentLevel);
TestExceptionFormatter exceptionFormatter = getExceptionFormatter(levelLogging);
TestEventLogger eventLogger = new TestEventLogger(getTextOutputFactory(), currentLevel, levelLogging, exceptionFormatter);
addTestListener(eventLogger);
addTestOutputListener(eventLogger);
TestExecutionSpec executionSpec = createTestExecutionSpec();
final File binaryResultsDir = getBinaryResultsDirectory().getAsFile().get();
FileSystemOperations fs = getFileSystemOperations();
fs.delete(new Action<DeleteSpec>() {
@Override
public void execute(DeleteSpec spec) {
spec.delete(binaryResultsDir);
}
});
binaryResultsDir.mkdirs();
Map<String, TestClassResult> results = new HashMap<String, TestClassResult>();
TestOutputStore testOutputStore = new TestOutputStore(binaryResultsDir);
TestOutputStore.Writer outputWriter = testOutputStore.writer();
TestReportDataCollector testReportDataCollector = new TestReportDataCollector(results, outputWriter);
addTestListener(testReportDataCollector);
addTestOutputListener(testReportDataCollector);
TestCountLogger testCountLogger = new TestCountLogger(getProgressLoggerFactory());
addTestListener(testCountLogger);
getTestListenerInternalBroadcaster().add(new TestListenerAdapter(testListenerBroadcaster.getSource(), getTestOutputListenerBroadcaster().getSource()));
ProgressLogger parentProgressLogger = getProgressLoggerFactory().newOperation(AbstractTestTask.class);
parentProgressLogger.setDescription("Test Execution");
parentProgressLogger.started();
TestWorkerProgressListener testWorkerProgressListener = new TestWorkerProgressListener(getProgressLoggerFactory(), parentProgressLogger);
getTestListenerInternalBroadcaster().add(testWorkerProgressListener);
TestExecuter<TestExecutionSpec> testExecuter = Cast.uncheckedNonnullCast(createTestExecuter());
TestListenerInternal resultProcessorDelegate = getTestListenerInternalBroadcaster().getSource();
if (failFast) {
resultProcessorDelegate = new FailFastTestListenerInternal(testExecuter, resultProcessorDelegate);
}
TestResultProcessor resultProcessor = new StateTrackingTestResultProcessor(resultProcessorDelegate);
try {
testExecuter.execute(executionSpec, resultProcessor);
} finally {
parentProgressLogger.completed();
testWorkerProgressListener.completeAll();
testListenerBroadcaster.removeAll();
getTestOutputListenerBroadcaster().removeAll();
getTestListenerInternalBroadcaster().removeAll();
outputWriter.close();
}
new TestResultSerializer(binaryResultsDir).write(results.values());
createReporting(results, testOutputStore);
handleCollectedResults(testCountLogger);
}
private void handleCollectedResults(TestCountLogger testCountLogger) {
if (testCountLogger.hadFailures()) {
handleTestFailures();
} else if (testCountLogger.getTotalTests() == 0 && shouldFailOnNoMatchingTests()) {
throw new TestExecutionException(createNoMatchingTestErrorMessage());
}
}
private boolean shouldFailOnNoMatchingTests() {
return filter.isFailOnNoMatchingTests() && (!filter.getIncludePatterns().isEmpty()
|| !filter.getCommandLineIncludePatterns().isEmpty()
|| !filter.getExcludePatterns().isEmpty());
}
private String createNoMatchingTestErrorMessage() {
return "No tests found for given includes: "
+ Joiner.on(' ').join(getNoMatchingTestErrorReasons());
}
/**
* Returns the reasons for no matching test error.
*
* @since 4.5
*/
@Internal
protected List<String> getNoMatchingTestErrorReasons() {
List<String> reasons = Lists.newArrayList();
if (!getFilter().getIncludePatterns().isEmpty()) {
reasons.add(getFilter().getIncludePatterns() + "(filter.includeTestsMatching)");
}
if (!filter.getCommandLineIncludePatterns().isEmpty()) {
reasons.add(filter.getCommandLineIncludePatterns() + "(--tests filter)");
}
return reasons;
}
private void createReporting(Map<String, TestClassResult> results, TestOutputStore testOutputStore) {
TestResultsProvider testResultsProvider = new InMemoryTestResultsProvider(results.values(), testOutputStore);
try {
if (testReporter == null) {
testReporter = new DefaultTestReport(getBuildOperationExecutor());
}
JUnitXmlReport junitXml = reports.getJunitXml();
if (junitXml.getRequired().get()) {
JUnitXmlResultOptions xmlResultOptions = new JUnitXmlResultOptions(
junitXml.isOutputPerTestCase(),
junitXml.getMergeReruns().get()
);
Binary2JUnitXmlReportGenerator binary2JUnitXmlReportGenerator = new Binary2JUnitXmlReportGenerator(junitXml.getOutputLocation().getAsFile().get(), testResultsProvider, xmlResultOptions, getBuildOperationExecutor(), getHostnameLookup().getHostname());
binary2JUnitXmlReportGenerator.generate();
}
DirectoryReport html = reports.getHtml();
if (!html.getRequired().get()) {
getLogger().info("Test report disabled, omitting generation of the HTML test report.");
} else {
testReporter.generateReport(testResultsProvider, html.getOutputLocation().getAsFile().getOrNull());
}
} finally {
CompositeStoppable.stoppable(testResultsProvider).stop();
testReporter = null;
}
}
/**
* Sets the test name patterns to be included in execution.
* Classes or method names are supported, wildcard '*' is supported.
* For more information see the user guide chapter on testing.
*
* For more information on supported patterns see {@link TestFilter}
*/
@Option(option = "tests", description = "Sets test class or method name to be included, '*' is supported.")
public AbstractTestTask setTestNameIncludePatterns(List<String> testNamePattern) {
filter.setCommandLineIncludePatterns(testNamePattern);
return this;
}
@Internal
boolean getFailFast() {
return failFast;
}
void setFailFast(boolean failFast) {
this.failFast = failFast;
}
/**
* The reports that this task potentially produces.
*
* @return The reports that this task potentially produces
*/
@Override
@Nested
public TestTaskReports getReports() {
return reports;
}
/**
* Configures the reports that this task potentially produces.
*
* @param closure The configuration
* @return The reports that this task potentially produces
*/
@Override
public TestTaskReports reports(Closure closure) {
return reports(new ClosureBackedAction<TestTaskReports>(closure));
}
/**
* Configures the reports that this task potentially produces.
*
* @param configureAction The configuration
* @return The reports that this task potentially produces
*/
@Override
public TestTaskReports reports(Action<? super TestTaskReports> configureAction) {
configureAction.execute(reports);
return reports;
}
private void handleTestFailures() {
String message = "There were failing tests";
DirectoryReport htmlReport = getReports().getHtml();
if (htmlReport.getRequired().get()) {
String reportUrl = new ConsoleRenderer().asClickableFileUrl(htmlReport.getEntryPoint());
message = message.concat(". See the report at: " + reportUrl);
} else {
DirectoryReport junitXmlReport = getReports().getJunitXml();
if (junitXmlReport.getRequired().get()) {
String resultsUrl = new ConsoleRenderer().asClickableFileUrl(junitXmlReport.getEntryPoint());
message = message.concat(". See the results at: " + resultsUrl);
}
}
if (getIgnoreFailures()) {
getLogger().warn(message);
} else {
throw new VerificationException(message);
}
}
/**
* Allows filtering tests for execution.
*
* @return filter object
* @since 1.10
*/
@Nested
public TestFilter getFilter() {
return filter;
}
}