Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid calling ClassResult.getChildren from tests #129

Merged
merged 1 commit into from
Jul 24, 2024
Merged
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 @@ -29,6 +29,8 @@
import hudson.tasks.junit.CaseResult;
import hudson.tasks.junit.ClassResult;
import hudson.tasks.junit.TestResultAction;
import hudson.tasks.test.TabulatedResult;
import hudson.tasks.test.TestResult;
import org.apache.commons.io.IOUtils;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
Expand Down Expand Up @@ -78,11 +80,11 @@ public void testWellKnownFilenamesAreAttached() throws Exception {
public void annotationDoesNotFailForPipeline() throws Exception {
TestResultAction action = getTestResultActionForPipeline("workspace2.zip", "pipelineTest.groovy", Result.UNSTABLE);

ClassResult cr = getClassResult(action, TEST_PACKAGE, "SignupTest");
Collection<CaseResult> caseResults = cr.getChildren();
TabulatedResult cr = getClassResult(action, TEST_PACKAGE, "SignupTest");
Collection<? extends TestResult> caseResults = cr.getChildren();
assertEquals(3, caseResults.size());

CaseResult failingCase = cr.getCaseResult("A_003_Type_the_text__jenkins__into_the_field__username_");
CaseResult failingCase = ((ClassResult) cr).getCaseResult("A_003_Type_the_text__jenkins__into_the_field__username_");
assertNotNull(failingCase);
assertEquals("Timed out after 10 seconds", failingCase.annotate(failingCase.getErrorDetails()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
import hudson.model.FreeStyleProject;
import hudson.model.Result;
import hudson.tasks.Builder;
import hudson.tasks.junit.CaseResult;
import hudson.tasks.junit.ClassResult;
import hudson.tasks.junit.JUnitResultArchiver;
import hudson.tasks.junit.PackageResult;
import hudson.tasks.junit.TestDataPublisher;
import hudson.tasks.junit.TestResultAction;
import hudson.tasks.test.TabulatedResult;
import hudson.tasks.test.TestResult;
import hudson.util.DescribableList;
import java.io.IOException;
Expand Down Expand Up @@ -88,8 +88,8 @@ public void testAttachmentsShownForClass_SignupTest() throws Exception {
public void testAttachmentsShownForTestcases_SignupTest() throws Exception {
TestResultAction action = getTestResultActionForBuild("workspace2.zip", Result.UNSTABLE);

ClassResult classResult = getClassResult(action, "SignupTest");
List<CaseResult> cases = new ArrayList<>(classResult.getChildren());
TabulatedResult classResult = getClassResult(action, "SignupTest");
List<TestResult> cases = new ArrayList<>(classResult.getChildren());
assertEquals(3, cases.size());

// Each test case should have the respective one attachment
Expand All @@ -103,8 +103,8 @@ public void testAttachmentsShownForTestcases_SignupTest() throws Exception {
public void testAttachmentsShownForTestcases_SignupTest_WithRunnerPrefix() throws Exception {
TestResultAction action = getTestResultActionForBuild("workspace3.zip", Result.UNSTABLE);

ClassResult classResult = getClassResult(action, "SignupTest");
List<CaseResult> cases = new ArrayList<>(classResult.getChildren());
TabulatedResult classResult = getClassResult(action, "SignupTest");
List<TestResult> cases = new ArrayList<>(classResult.getChildren());
assertEquals(3, cases.size());

// Each test case should have the respective one attachment
Expand All @@ -127,8 +127,8 @@ public void testAttachmentsShownForClass_LoginTest() throws Exception {
public void testAttachmentsShownForTestcases_LoginTest() throws Exception {
TestResultAction action = getTestResultActionForBuild("workspace2.zip", Result.UNSTABLE);

ClassResult classResult = getClassResult(action, "LoginTest");
List<CaseResult> cases = new ArrayList<>(classResult.getChildren());
TabulatedResult classResult = getClassResult(action, "LoginTest");
List<TestResult> cases = new ArrayList<>(classResult.getChildren());
assertEquals(4, cases.size());

// Each test case should have the respective one (or zero) attachments
Expand All @@ -154,8 +154,8 @@ public void testAttachmentsShownForClass_MiscTest1() throws Exception {
public void testAttachmentsShownForTestcases_MiscTest1() throws Exception {
TestResultAction action = getTestResultActionForBuild("workspace2.zip", Result.UNSTABLE);

ClassResult classResult = getClassResult(action, "MiscTest1");
List<CaseResult> cases = new ArrayList<>(classResult.getChildren());
TabulatedResult classResult = getClassResult(action, "MiscTest1");
List<TestResult> cases = new ArrayList<>(classResult.getChildren());
assertEquals(1, cases.size());

// Attachment should not be inherited from testsuite
Expand All @@ -177,8 +177,8 @@ public void testAttachmentsShownForClass_MiscTest2() throws Exception {
public void testAttachmentsShownForTestcases_MiscTest2() throws Exception {
TestResultAction action = getTestResultActionForBuild("workspace2.zip", Result.UNSTABLE);

ClassResult classResult = getClassResult(action, "MiscTest2");
List<CaseResult> cases = new ArrayList<>(classResult.getChildren());
TabulatedResult classResult = getClassResult(action, "MiscTest2");
List<TestResult> cases = new ArrayList<>(classResult.getChildren());
assertEquals(2, cases.size());

// Alphabetically first comes the "doNothing" test
Expand Down