Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class VsTestBuilder extends Builder implements SimpleBuildStep {
private boolean useVs2017Plus;
private boolean enablecodecoverage = DescriptorImpl.defaultEnableCodeCoverage;
private boolean failBuild = DescriptorImpl.defaultFailBuild;

private boolean skipIfNoTests = DescriptorImpl.defaultSkipIfNoTests;
@DataBoundConstructor
public VsTestBuilder() {

Expand Down Expand Up @@ -136,6 +136,10 @@ public boolean isFailBuild() {
return failBuild;
}

public boolean isSkipIfNoTests() {
return skipIfNoTests;
}

@DataBoundSetter
public void setVsTestName(String vsTestName) {
this.vsTestName = Util.fixEmptyAndTrim(vsTestName);
Expand Down Expand Up @@ -209,6 +213,11 @@ public void setFailBuild(boolean failBuild) {
this.failBuild = failBuild;
}

@DataBoundSetter
public void setSkipIfNoTests(boolean skipIfNoTests) {
this.skipIfNoTests = skipIfNoTests;
}

@NonNull
public VsTestInstallation getVsTest(TaskListener listener) {
if (vsTestName == null) return VsTestInstallation.getDefaultInstallation();
Expand All @@ -234,6 +243,7 @@ public DescriptorImpl getDescriptor() {
public static final class DescriptorImpl extends BuildStepDescriptor<Builder> {

public static final boolean defaultFailBuild = true;
public static final boolean defaultSkipIfNoTests = false;
public static final boolean defaultEnableCodeCoverage = true;
public static final String defaultLogger = VsTestLogger.TRX.toString();

Expand Down Expand Up @@ -313,11 +323,12 @@ public void perform(@NonNull Run<?, ?> run, @NonNull FilePath workspace, @NonNul
args.add(pathToVsTest);

// Target dll path
List<String> targets = new ArrayList<>();
if (!StringUtils.isBlank(testFiles)) {
List<String> targets = getTestFilesArguments(workspace, env);
targets = getTestFilesArguments(workspace, env);
if (targets.size() == 0) {
listener.getLogger().println("no files matching the pattern " + this.testFiles);
if (this.failBuild) {
if (this.failBuild && !this.skipIfNoTests) {
run.setResult(Result.FAILURE);
throw new AbortException("no files matching the pattern " + this.testFiles);
}
Expand Down Expand Up @@ -382,8 +393,14 @@ public void perform(@NonNull Run<?, ?> run, @NonNull FilePath workspace, @NonNul
args.add(replaceMacro(cmdLineArgs, env));
}

// VSTest run.
execVsTest(args, run, workspace, launcher, listener, env);
if (targets.isEmpty() && this.skipIfNoTests) {
// Skip running non-existing tests
listener.getLogger().println("No test files were found, skip running tests.");
}
else {
// VSTest run.
execVsTest(args, run, workspace, launcher, listener, env);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@
<f:checkbox default="${descriptor.defaultFailBuild}"/>
</f:entry>

<f:entry title="${%Skip if no tests}" field="skipIfNoTests">
<f:checkbox default="${descriptor.defaultSkipIfNoTests}"/>
</f:entry>

</f:advanced>

</j:jelly>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div>
<p>
If this is checked and no test files are found the test execution will be skipped.
</p>
</div>