Skip to content
This repository has been archived by the owner on Jan 18, 2021. It is now read-only.

Initial design for Build A/B testing epic story #114

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
step 2. Run A test
step 3. Run B test
  • Loading branch information
epeee committed May 15, 2017
commit 2899e4645d2986f6dfd3f8cad74c96c6eb0cde49
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package org.mockito.release.internal.gradle;

import org.gradle.api.Action;
import org.gradle.api.DefaultTask;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.file.CopySpec;
import org.gradle.api.tasks.*;
import org.mockito.release.exec.DefaultProcessRunner;

Expand All @@ -22,18 +24,18 @@ public void apply(final Project project) {
//Step 2. Run A test
RunTestTask runA = project.getTasks().create("runA", RunTestTask.class);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can reuse RunTestReleaseTask

runA.dependsOn(clone);
runA.setSourceDir(clone.getTargetDir());
runA.setSourceDir(new File(clone.getTargetDir(), "mockito"));
runA.setWorkDir(new File(project.getBuildDir(), "abTesting/mockito/testA-" + System.currentTimeMillis()));
runA.commandLine("./gradlew", "build");
runA.setOutputDir(new File(runA.getWorkDir(), "build"));

//Step 3. Run B test
RunTestTask runB = project.getTasks().create("runB", RunTestTask.class);
runA.dependsOn(clone);
runA.setSourceDir(clone.getTargetDir());
runA.setWorkDir(new File(project.getBuildDir(), "abTesting/mockito/testB-" + System.currentTimeMillis()));
runA.commandLine("./gradlew", "build");
runA.setOutputDir(new File(runA.getWorkDir(), "build"));
runB.dependsOn(clone);
runB.setSourceDir(new File(clone.getTargetDir(), "mockito"));
runB.setWorkDir(new File(project.getBuildDir(), "abTesting/mockito/testB-" + System.currentTimeMillis()));
runB.commandLine("./gradlew", "build");
runB.setOutputDir(new File(runB.getWorkDir(), "build"));

//Step 4. Compare test outcomes
CompareDirectoriesTask compare = project.getTasks().create("compareAB", CompareDirectoriesTask.class);
Expand Down Expand Up @@ -94,6 +96,7 @@ public static class RunTestTask extends DefaultTask {
private File sourceDir;
private File workDir;
private File outputDir;
private String[] arg;

@InputDirectory
public void setSourceDir(File sourceDir) {
Expand All @@ -106,20 +109,34 @@ public void setWorkDir(File workDir) {

@Input
public void commandLine(String ... arg) {
this.arg = arg;
}

public File getWorkDir() {
return workDir;
}

@OutputDirectory
public void setOutputDir(File outputDir) {
this.outputDir = outputDir;
}

@OutputDirectory
public File getOutputDir() {
return outputDir;
}

@TaskAction
public void executeTestTask() {
if (outputDir != null && !outputDir.exists()) {
outputDir.mkdirs();
}
getProject().copy(new Action<CopySpec>() {
public void execute(CopySpec copy) {
copy.from(sourceDir).into(workDir);
}
});
new DefaultProcessRunner(workDir).run(arg);
}
}

public static class CompareABTask extends DefaultTask {
Expand Down Expand Up @@ -147,7 +164,7 @@ public File getTargetDir() {

@TaskAction
public void cloneGit() {
if(!targetDir.exists()) {
if(targetDir != null && !targetDir.exists()) {
targetDir.mkdirs();
}

Expand Down