Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Added flag to fail execution when no test classes exist for specified manifest and/or regex only if it's set to true #80

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ Optional Parameters:
- -max.test.execution.time.threshold : Maximum execution time(in minutes) for a test before it gets aborted
- -proxy.host : Proxy host for external access
- -proxy.port : Proxy port for external access
- -require.at.least.one.test : Fail if no test classes exist for specified manifest and/or regex pattern (defaults to `true`)
- -help : Displays options available for running this application

Note: You must provide either of the (-regex.for.selecting.source.classes.for.code.coverage.computation OR -manifest.files.with.source.class.names.for.code.coverage.computation) AND either of -(regex.for.selecting.test.classes.to.execute OR -manifest.files.with.test.class.names.to.execute)
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/sforce/cd/apexUnit/ApexUnitRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public static void main(String[] args) {
LOG.info("Total test methods executed: " + apexReportBeans.length);
String reportFile = "ApexUnitReport.xml";
ApexUnitTestReportGenerator.generateTestReport(apexReportBeans, reportFile);
} else {
} else if (CommandLineArguments.isRequireAtLeastOneTest()) {
ApexUnitUtils.shutDownWithErrMsg("Unable to generate test report. "
+ "Did not find any test results for the job id");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public class CommandLineArguments {
public static final String PROXY_HOST = "-proxy.host";
public static final String PROXY_PORT = "-proxy.port";
public static final String TEST_RELOAD = "-test.reload";

public static final String REQUIRE_AT_LEAST_ONE_TEST = "-require.at.least.one.test";

public static final String HELP = "-help";

/*
Expand Down Expand Up @@ -79,6 +80,8 @@ public class CommandLineArguments {
static private boolean help;
@Parameter(names = TEST_RELOAD, description = "Want to reload test if same class changes submitted again.", arity=1)
static private boolean testReload;
@Parameter(names = REQUIRE_AT_LEAST_ONE_TEST, description = "Fail if no test classes exist for specified manifest and/or regex pattern (defaults to true)", arity=1)
static private boolean requireAtLeastOneTest = true;

/*
* Static getter methods for each of the CLI parameter
Expand Down Expand Up @@ -152,5 +155,9 @@ public static boolean isHelp() {
public static boolean isTestReload() {
return testReload;
}

public static boolean isRequireAtLeastOneTest() {
return requireAtLeastOneTest;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public CodeCoverageComputer() {
public ApexClassCodeCoverageBean[] calculateAggregatedCodeCoverageUsingToolingAPI() {
PartnerConnection connection = ConnectionHandler.getConnectionHandlerInstance().getConnection();

ApexClassCodeCoverageBean[] apexClassCodeCoverageBeans = null;
ApexClassCodeCoverageBean[] apexClassCodeCoverageBeans = new ApexClassCodeCoverageBean[0];
String[] classesAsArray = null;

/*
Expand Down Expand Up @@ -184,7 +184,7 @@ public ApexClassCodeCoverageBean[] calculateAggregatedCodeCoverageUsingToolingAP
"Code coverage metrics not computed. Null object returned while processing the JSON response from the Tooling API");
}
}
} else {
} else if (CommandLineArguments.isRequireAtLeastOneTest()) {
ApexUnitUtils.shutDownWithErrMsg("No/Invalid Apex source classes mentioned in manifest file and/or "
+ "regex pattern for ApexSourceClassPrefix didn't return any Apex source class names from the org");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ public ApexReportBean[] testExecutionFlow() {
if (LOG.isDebugEnabled()) {
ApexClassFetcherUtils.logTheFetchedApexClasses(testClassesAsArray);
}
if (testClassesAsArray == null || testClassesAsArray.length == 0) {
return null;
}
String soql = QueryConstructor.getQueryForApexClassInfo(processClassArrayForQuery(testClassesAsArray));
QueryResult queryresult = null;
try {
Expand Down Expand Up @@ -93,12 +96,9 @@ public ApexReportBean[] testExecutionFlow() {

}

if(!submitTest){
if(!submitTest) {
ApexUnitUtils.shutDownWithErrMsg("Test for these classes already running/enqueue at server...");
}
else{

if (testClassesAsArray != null && testClassesAsArray.length > 0) {
} else {

int numOfBatches = 0;
int fromIndex = 0;
Expand All @@ -122,7 +122,7 @@ public ApexReportBean[] testExecutionFlow() {

testClassesInBatch = Arrays.copyOfRange(testClassesAsArray, fromIndex, toIndex);
parentJobId = bulkApiHandler.handleBulkApiFlow(conn, bulkConnection, testClassesInBatch);

LOG.info("#####Parent JOB ID #####"+parentJobId);
if (parentJobId != null) {
LOG.info("Parent job ID for the submission of the test classes to the Force.com platform is: "
Expand All @@ -138,8 +138,7 @@ public ApexReportBean[] testExecutionFlow() {
}

}

}

}
return apexReportBean.toArray(new ApexReportBean[0]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ public static String[] constructTestClassesArray(PartnerConnection connection) {
consolidatedTestClassesAsArray = testClassesAsArray;
}
// if null, no apex test classes fetched to execute; throw warning
if (consolidatedTestClassesAsArray == null || consolidatedTestClassesAsArray.length == 0) {
if (CommandLineArguments.isRequireAtLeastOneTest()
&& (consolidatedTestClassesAsArray == null || consolidatedTestClassesAsArray.length == 0)) {
ApexUnitUtils.shutDownWithErrMsg("No/Invalid test classes mentioned in manifest file and/or "
+ "regex pattern for ApexTestPrefix didn't return any test class names from the org");
} else {
Expand Down