org.gradle.api.tasks.testing.Test类的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(14.2k)|赞(0)|评价(0)|浏览(156)

本文整理了Java中org.gradle.api.tasks.testing.Test类的一些代码示例,展示了Test类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Test类的具体详情如下:
包路径:org.gradle.api.tasks.testing.Test
类名称:Test

Test介绍

暂无

代码示例

代码示例来源:origin: uber/okbuck

@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);
}

代码示例来源:origin: gradle.plugin.org.javamodularity/moduleplugin

testJava.getExtensions().create("moduleOptions", TestModuleOptions.class, project);
testJava.doFirst(task -> {
  TestModuleOptions testModuleOptions = testJava.getExtensions().getByType(TestModuleOptions.class);
  if (testModuleOptions.isRunOnClasspath()) {
    LOGGER.lifecycle("Running tests on classpath");
  var args = new ArrayList<>(testJava.getJvmArgs());
      "--module-path", testJava.getClasspath().getAsPath(),
      "--patch-module", moduleName + "=" + testSourceSet.getJava().getOutputDir().toPath(),
      "--add-modules", "ALL-MODULE-PATH"
  testJava.setJvmArgs(args);
  testJava.setClasspath(project.files());
});

代码示例来源:origin: gradle.plugin.rgoldberg/java-modules

private void configureTestTask(final Test test, final ImmutableSet<String> moduleNameIset) {
  setModuleNamesInputProperty(test, moduleNameIset);
  test.doFirst(task -> {
    final Project project = test.getProject();
    final List<String> args = test.getJvmArgs();
    addModulePathArgument(args, test.getClasspath());
    args.add(OPTION_ADD_MODULES);
    args.add(ALL_MODULE_PATH);
    KnownTestFrameworkModuleInfo.from(test).configureTestTask(args, moduleNameIset);
    addPatchModuleArguments(args, moduleNameIset, project.files(getSourceSets(project).getByName(TEST_SOURCE_SET_NAME).getJava().getOutputDir()));
    test.setClasspath(project.files());
  });
}

代码示例来源:origin: gradle.plugin.com.intershop.gradle.plugin.azure/azurePlugin

@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" ));
  }
}

代码示例来源:origin: gradle.plugin.ru.javasaw/javasaw

@Override
public void configure(Task task) {
  LOGGER.info("running configurer for :" + task.getName());
  Test test = (Test) task;
  ModuleDefinition moduleDefinition = moduleInfoService.findModuleDefinition( task.getProject().getName()).orElse(null);
  if (moduleDefinition == null) {
    throw new IllegalStateException("Cant find module definition for " + task.getProject().getName() + " inside task " + task.getName());
  }
  test.doFirst(action -> {
    JavaSawExtension extension = (JavaSawExtension) project.getExtensions().getByName(JAVA_SAW_TEST_EXT_NAME);
    JavaCompileTaskArgs compilerArgs = argsPatcher.patch(test.getClasspath().getAsPath(), extension, moduleDefinition);
    CompileArg arg = compilerArgs.getArgByName(JavaCompileTaskArgs.MODULE_PATH);
    arg.getArguments().addAll(mainOutputDirsPath());
    List<String> compilerResultArgs = compilerArgs.getCompilerResultArgs();
    compilerResultArgs.add(ADD_READS);
    compilerResultArgs.add(moduleDefinition.getName() + "=" + "org.junit.jupiter.api"); // todo
    compilerResultArgs.add(PATCH_MODULE);
    compilerResultArgs.add(moduleDefinition.getName() + "=" + testOutputDirsPath());
    compilerResultArgs.add(ADD_MODULE);
    compilerResultArgs.add("ALL-MODULE-PATH"); // todo
    test.setJvmArgs(compilerResultArgs);
    LOGGER.debug("result jvm arguments is : " + test.getJvmArgs());
  });
}
private List<String> mainOutputDirsPath() {

代码示例来源:origin: gradle.plugin.de.monkeyworks.buildmonkey/gradle.pde

private List<String> collectTestNames(Test testTask) {
  ClassNameCollectingProcessor processor = new ClassNameCollectingProcessor();
  Runnable detector;
  final FileTree testClassFiles = testTask.getCandidateClassFiles();
  if (testTask.isScanForTestClasses()) {
    TestFrameworkDetector testFrameworkDetector = testTask.getTestFramework().getDetector();
    testFrameworkDetector.setTestClassesDirectory(testTask.getTestClassesDir());
    testFrameworkDetector.setTestClasspath(testTask.getClasspath());
    detector = new PluginTestClassScanner(testClassFiles, processor);
  } else {
    detector = new PluginTestClassScanner(testClassFiles, processor);
  }
  final Object testTaskOperationId = OperationIdGenerator.generateId(testTask);
  new TestMainAction(detector, processor, new NoOpTestResultProcessor(), new TrueTimeProvider(), testTaskOperationId, testTask.getPath(), String.format("Gradle Eclipse Test Run %s", testTask.getPath())).run();
  LOGGER.info("collected test class names: {}", processor.classNames);
  return processor.classNames;
}

代码示例来源:origin: gradle.plugin.org.gradle.java/experimental-jigsaw

@Override
  public void execute(Task task) {
    List<String> args = new ArrayList<>();
    args.add("--module-path");
    args.add(testTask.getClasspath().getAsPath());
    args.add("--add-modules");
    args.add("ALL-MODULE-PATH");
    args.add("--add-reads");
    args.add(module.geName() + "=junit");
    args.add("--patch-module");
    args.add(module.geName() + "=" + test.getJava().getOutputDir());
    testTask.setJvmArgs(args);
    testTask.setClasspath(project.files());
  }
});

代码示例来源:origin: com.tngtech.jgiven/jgiven-gradle-plugin

private void applyTo( Test test ) {
  final String testName = test.getName();
  final JGivenTaskExtension extension = test.getExtensions().create( "jgiven", JGivenTaskExtension.class );
  final Project project = test.getProject();
  ( (IConventionAware) extension ).getConventionMapping().map( "resultsDir", new Callable<File>() {
    @Override
    public File call() {
      return project.file( String.valueOf( project.getBuildDir() ) + "/jgiven-results/" + testName );
    }
  } );
  File resultsDir = extension.getResultsDir();
  if( resultsDir != null ) {
    test.getOutputs().dir(resultsDir).withPropertyName("jgiven.resultsDir");
  }
  test.prependParallelSafeAction( new Action<Task>() {
    @Override
    public void execute( Task task ) {
      Test test = (Test) task;
      test.systemProperty( Config.JGIVEN_REPORT_DIR, extension.getResultsDir().getAbsolutePath() );
    }
  } );
}

代码示例来源:origin: gradle.plugin.com.intershop.gradle.plugin.azure/azurePlugin

@Override
  void configure(Task task)
  {
    super.configure(task);

    Task prepareTestEnvTask = project.getTasks().findByName(AzurePlugin.PREPARE_TEST_ENV_TASK);

    Task cleanupTestEnvTask = project.getTasks().findByName(AzurePlugin.CLEANUP_TEST_ENV_TASK);

    Task triggerTestCleanUpTask = project.getTasks().findByName(AzurePlugin.TRIGGER_CLEAN_TEST_ENV);

    Test t = (Test)task;

    t.setDescription("Test execution of the azureTest source set.");

    t.dependsOn(prepareTestEnvTask, triggerTestCleanUpTask);

    t.finalizedBy(cleanupTestEnvTask);

    t.setClasspath(sourceSet.getRuntimeClasspath());
    t.setTestClassesDirs(sourceSet.getOutput().getClassesDirs());

    t.systemProperty("testEnvPath", azure.getTestEnvFile().get().getAsFile().getAbsolutePath());

  }
}

代码示例来源:origin: gradle.plugin.de.monkeyworks.buildmonkey/gradle.pde

private void runPluginTestsInEclipse(final Test testTask, final TestResultProcessor testResultProcessor,
    final int pluginTestPort) {
  ExecutorService threadPool = Executors.newFixedThreadPool(2);
  File runDir = new File(testTask.getProject().getBuildDir(), testTask.getName());
  javaExecHandleBuilder.setSystemProperties(testTask.getSystemProperties());
  javaExecHandleBuilder.setEnvironment(testTask.getEnvironment());

代码示例来源:origin: com.amazon.device.tools.build/gradle-core

variantData.getScope().getTaskName(UNIT_TEST.getPrefix()),
    Test.class);
runTestsTask.setGroup(JavaBasePlugin.VERIFICATION_GROUP);
runTestsTask.setDescription(
    "Run unit tests for the " +
        testedVariantData.getVariantConfiguration().getFullName() + " build.");
runTestsTask.dependsOn(variantData.assembleVariantTask);
runTestsTask.setTestClassesDir(testCompileTask.getDestinationDir());
TestTaskReports testTaskReports = runTestsTask.getReports();

代码示例来源:origin: typelead/gradle-eta

private void execute(Test test, TestResultProcessor resultProcessor) {
  execute(execSpec -> {
      test.copyTo(execSpec);
      execSpec.setClasspath(test.getClasspath());
    }, resultProcessor);
}

代码示例来源:origin: gradle.plugin.org.gradle.java/experimental-jigsaw

private void configureTestTask(final Project project) {
  final Test testTask = (Test) project.getTasks().findByName(JavaPlugin.TEST_TASK_NAME);
  final SourceSet test = ((SourceSetContainer) project.getProperties().get("sourceSets")).getByName("test");
  final JavaModule module = (JavaModule) project.getExtensions().getByName(EXTENSION_NAME);
  testTask.getInputs().property("moduleName", module.geName());
  testTask.doFirst(new Action<Task>() {
    @Override
    public void execute(Task task) {
      List<String> args = new ArrayList<>();
      args.add("--module-path");
      args.add(testTask.getClasspath().getAsPath());
      args.add("--add-modules");
      args.add("ALL-MODULE-PATH");
      args.add("--add-reads");
      args.add(module.geName() + "=junit");
      args.add("--patch-module");
      args.add(module.geName() + "=" + test.getJava().getOutputDir());
      testTask.setJvmArgs(args);
      testTask.setClasspath(project.files());
    }
  });
}

代码示例来源:origin: palantir/gradle-baseline

private void configurePluginsForArtifacts(Project project) {
  String circleArtifactsDir = System.getenv("CIRCLE_ARTIFACTS");
  if (circleArtifactsDir == null) {
    project.getLogger().info("$CIRCLE_ARTIFACTS variable is not set, not configuring junit/profiling reports");
    return;
  }
  try {
    Files.createDirectories(Paths.get(circleArtifactsDir), PERMS_ATTRIBUTE);
  } catch (IOException e) {
    throw new RuntimeException("failed to create CIRCLE_ARTIFACTS directory", e);
  }
  project.getRootProject().allprojects(proj ->
      proj.getTasks().withType(Test.class, test -> {
        test.getReports().getHtml().setEnabled(true);
        test.getReports().getHtml().setDestination(junitPath(circleArtifactsDir, test.getPath()));
      }));
}

代码示例来源:origin: steffenschaefer/gwt-gradle-plugin

@Override
  public void execute(final Test testTask) {
    testTask.getTestLogging().setShowStandardStreams(true);
    
    final GwtTestExtension testExtension = testTask.getExtensions().create("gwt", GwtTestExtension.class);
    testExtension.configure(gwtPluginExtension, (IConventionAware) testExtension);
    
    project.afterEvaluate(new Action<Project>() {
      @Override
      public void execute(Project t) {
        String gwtArgs = testExtension.getParameterString();
        testTask.systemProperty("gwt.args", gwtArgs);
        logger.info("Using gwt.args for test: "+ gwtArgs);
        
        if (testExtension.getCacheDir() != null) {
          testTask.systemProperty("gwt.persistentunitcachedir", testExtension.getCacheDir());
          testExtension.getCacheDir().mkdirs();
          logger.info("Using gwt.persistentunitcachedir for test: {0}", testExtension.getCacheDir());
        }
      }
    });
    
    project.getPlugins().withType(GwtWarPlugin.class, new Action<GwtWarPlugin>() {
      @Override
      public void execute(GwtWarPlugin t) {
        testTask.dependsOn(GwtWarPlugin.TASK_WAR_TEMPLATE);
      }});
  }
});

代码示例来源:origin: com.tngtech.jgiven/jgiven-gradle-plugin

@Override
  public File call() {
    return test.getExtensions().getByType( JGivenTaskExtension.class ).getResultsDir();
  }
} );

代码示例来源:origin: org.sonarsource.scanner.gradle/sonarqube-gradle-plugin

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);
 }
}

代码示例来源:origin: gradle.plugin.de.uni-passau.fim.prog1pa/GradlePlugin

/**
 * 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);
}

代码示例来源:origin: Putnami/putnami-gradle-plugin

private void includeSourcesForTest(Project project) {
  JavaPluginConvention javaConvention = project.getConvention().getPlugin(JavaPluginConvention.class);
  SourceSet mainSourset = javaConvention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME);
  SourceSet testSourset = javaConvention.getSourceSets().getByName(SourceSet.TEST_SOURCE_SET_NAME);
  FileCollection testClasspath = project
    .files(mainSourset.getAllSource().getSrcDirs().toArray())
    .plus(project.files(testSourset.getAllSource().getSrcDirs().toArray()))
    .plus(testSourset.getRuntimeClasspath());
  testSourset.setRuntimeClasspath(testClasspath);
  Test test = project.getTasks().withType(Test.class).getByName("test");
  test.getSystemProperties().put("gwt.persistentunitcachedir", project.getBuildDir() + "/putnami/test");
}

代码示例来源:origin: gradle.plugin.de.monkeyworks.buildmonkey/gradle.pde

private PluginTestExtension getExtension(Test testTask) {
  return (PluginTestExtension) testTask.getProject().getExtensions().findByName("pluginTest");
}

相关文章