@Option(option = "aws-profile", description = "AWS credential profile to use for test", order = 2) public void setProfile(String profile) { super.systemProperty(AWS_PROFILE, profile); }
/** * The test options * * @return The test options */ public TestOptions getTestOptions() { Test testTask = (Test) getProject().getTasks().getByName(JavaPlugin.TEST_TASK_NAME); Map<String, Object> env = testTask.getEnvironment(); env.keySet().removeAll(System.getenv().keySet()); return new TestOptions(testTask.getAllJvmArgs(), testTask.getEnvironment()); }
@Override public TestOptions getTestOptions() { String testTaskName = VariantType.UNIT_TEST_PREFIX + StringUtils.capitalize(getName()) + VariantType.UNIT_TEST_SUFFIX; List<Test> testTasks = ImmutableList.copyOf(getProject().getTasks().withType(Test.class)); Optional<Test> optionalTest = testTasks.stream().filter(test -> test.getName().equals(testTaskName)).findFirst(); List<String> jvmArgs = optionalTest.map(Test::getAllJvmArgs).orElseGet(Collections::<String>emptyList); Map<String, Object> env = optionalTest.map(Test::getEnvironment).orElseGet(Collections::emptyMap); System.getenv().keySet().forEach(env::remove); return new TestOptions(jvmArgs, env); }
@Override public void apply( Project project ) { project.getTasks().withType( Test.class ).configureEach( task -> { task.useJUnitPlatform(); task.testLogging( log -> log.info( info -> info.getEvents().add( TestLogEvent.PASSED ) ) ); task.reports( reports -> { reports.getJunitXml().setEnabled( true ); reports.getHtml().setEnabled( false ); } ); } ); } }
@Override void configure(Task task) { super.configure(task); Task prepareMonitorEnvTask = project.getTasks().findByName(AzurePlugin.PREPARE_MONITOR_ENV_TASK); Test t = (Test)task; t.setDescription("Test execution of the azureTest source set against production deployment."); t.dependsOn(prepareMonitorEnvTask); t.setClasspath(sourceSet.getRuntimeClasspath()); t.setTestClassesDirs(sourceSet.getOutput().getClassesDirs()); t.systemProperty("testEnvPath", azure.getMonitorEnvFile().get().getAsFile().getAbsolutePath()); t.setBinResultsDir(new File(project.getBuildDir(), "monitor-test-results/binary/test")); t.getReports().getHtml().setDestination(new File(project.getBuildDir(), "reports/monitor-test-results" )); t.getReports().getJunitXml().setDestination(new File(project.getBuildDir(), "monitor-test-results" )); } }
private static void configureTestReports(Test testTask, Map<String, Object> properties) { File testResultsDir = testTask.getReports().getJunitXml().getDestination(); // do not set a custom test reports path if it does not exists, otherwise SonarQube will emit an error // do not set a custom test reports path if there are no files, otherwise SonarQube will emit a warning if (testResultsDir.isDirectory() && asList(testResultsDir.list()).stream().anyMatch(file -> TEST_RESULT_FILE_PATTERN.matcher(file).matches())) { appendProp(properties, "sonar.junit.reportPaths", testResultsDir); // For backward compatibility appendProp(properties, "sonar.junit.reportsPath", testResultsDir); appendProp(properties, "sonar.surefire.reportsPath", testResultsDir); } }
/** * Configures the {@link Test} task to produces a shorter output when executing tests. * * @param project * the {@link Project} that the {@link Plugin} is applied to */ private void configureTestTask(Project project) { Test test = (Test) project.getTasks().getByName("test"); TestLoggingContainer testLogging = test.getTestLogging(); testLogging.events("failed", "passed"); testLogging.setExceptionFormat(TestExceptionFormat.FULL); testLogging.setShowStackTraces(false); }
private void execute(Test test, TestResultProcessor resultProcessor) { execute(execSpec -> { test.copyTo(execSpec); execSpec.setClasspath(test.getClasspath()); }, resultProcessor); }
private PluginTestExtension getExtension(Test testTask) { return (PluginTestExtension) testTask.getProject().getExtensions().findByName("pluginTest"); }
@Override public File call() { return test.getExtensions().getByType( JGivenTaskExtension.class ).getResultsDir(); } } );
public static KnownTestFrameworkModuleInfo from(final Test test) { return TEST_FRAMEWORK_IBY_CLASS_NAME.getOrDefault(test.getTestFramework().getClass().getName(), UNKNOWN); } }
private static void fixTestTaskSources(@NonNull Test testTask) { // We are running in afterEvaluate, so the JavaBasePlugin has already added a // callback to add test classes to the list of source files of the newly created task. // The problem is that we haven't configured the test classes yet (JavaBasePlugin // assumes all Test tasks are fully configured at this point), so we have to remove the // "directory null" entry from source files and add the right value. // // This is an ugly hack, since we assume sourceFiles is an instance of // DefaultConfigurableFileCollection. ((DefaultConfigurableFileCollection) testTask.getInputs().getSourceFiles()).getFrom().clear(); }
/** * Returns the test class files. * * <p>This is the special case we need to handle - if getCandidateClassFiles is called * too early, i.e. before the task is fully configured, return an empty FileTree. The * default is to create a FileTree using getTestClassesDir(), but that creates a * FileTree with a null root, which fails later on. * * @see ConfigAction#configureSources(AndroidUnitTest) */ @Override public FileTree getCandidateClassFiles() { if (getTestClassesDir() == null) { return getProject().files().getAsFileTree(); } else { return super.getCandidateClassFiles(); } }
@Override public void apply( Project project ) { project.getPluginManager().apply( JavaLibraryPlugin.class ); DependencyHandler deps = project.getDependencies(); deps.add( TEST_IMPL, String.join( D, Junit.G, Junit.Api.A ) ); deps.add( TEST_IMPL, String.join( D, Junit.G, Junit.Param.A ) ); deps.add( TEST_RUN, String.join( D, Junit.G, Junit.Engine.A ) ); deps.add( TEST_IMPL, String.join( D, AssertJ.G, AssertJ.A ) ); project.getTasks().withType( Test.class ).configureEach( task -> { task.useJUnitPlatform(); task.testLogging( log -> log.info( info -> info.getEvents().add( TestLogEvent.PASSED ) ) ); task.reports( reports -> { reports.getJunitXml().setEnabled( true ); reports.getHtml().setEnabled( false ); } ); } ); } }
private static void configureTestReports(Test testTask, Map<String, Object> properties) { File testResultsDir = testTask.getReports().getJunitXml().getDestination(); // do not set a custom test reports path if it does not exists, otherwise SonarQube will emit an error // do not set a custom test reports path if there are no files, otherwise SonarQube will emit a warning if (testResultsDir.isDirectory() && asList(testResultsDir.list()).stream().anyMatch(file -> TEST_RESULT_FILE_PATTERN.matcher(file).matches())) { appendProp(properties, "sonar.junit.reportPaths", testResultsDir); // For backward compatibility appendProp(properties, "sonar.junit.reportsPath", testResultsDir); appendProp(properties, "sonar.surefire.reportsPath", testResultsDir); } }
@Option(option = "aws-region", description = "AWS region to use for test", order = 1) public void setRegion(String region) { super.systemProperty(AWS_REGION, region); }
@Override public void execute( final Test test ) { final JGivenReportTask reportTask = project.getTasks() .create( "jgiven" + WordUtil.capitalize( test.getName() ) + "Report", JGivenReportTask.class ); configureDefaultReportTask( test, reportTask, reportingExtension ); } } );
private FileResolver getFileResolver(Test testTask) { return testTask.getProject().getPlugins().findPlugin(PluginTestPlugin.class).fileResolver; }
@Option(option = "endpoint", description = "Blox service endpoint", order = 3) public void setEndpoint(String endpoint) { super.systemProperty(BLOX_ENDPOINT, endpoint); }
@Override public void execute( Task task ) { Test test = (Test) task; test.systemProperty( Config.JGIVEN_REPORT_DIR, extension.getResultsDir().getAbsolutePath() ); } } );