This repository was archived by the owner on Mar 27, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
Add tests for Test Result Visualization #427
Closed
Closed
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
340 changes: 340 additions & 0 deletions
340
src/test/java/com/mathworks/ci/systemtests/TestResultVisualizationIT.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,340 @@ | ||||||
| package com.mathworks.ci.systemtests; | ||||||
|
|
||||||
| import com.mathworks.ci.MatlabBuildWrapperContent; | ||||||
| import com.mathworks.ci.MatlabInstallationAxis; | ||||||
| import com.mathworks.ci.Message; | ||||||
| import com.mathworks.ci.UseMatlabVersionBuildWrapper; | ||||||
| import com.mathworks.ci.freestyle.RunMatlabBuildBuilder; | ||||||
| import com.mathworks.ci.freestyle.RunMatlabCommandBuilder; | ||||||
| import com.mathworks.ci.freestyle.RunMatlabTestsBuilder; | ||||||
| import hudson.matrix.*; | ||||||
| import hudson.model.FreeStyleBuild; | ||||||
| import hudson.model.FreeStyleProject; | ||||||
| import hudson.model.Result; | ||||||
| import hudson.model.Run; | ||||||
| import hudson.slaves.DumbSlave; | ||||||
| import org.htmlunit.html.*; | ||||||
| import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition; | ||||||
| import org.jenkinsci.plugins.workflow.job.WorkflowJob; | ||||||
| import org.jenkinsci.plugins.workflow.job.WorkflowRun; | ||||||
| import org.junit.*; | ||||||
| import org.jvnet.hudson.test.ExtractResourceSCM; | ||||||
| import org.jvnet.hudson.test.JenkinsRule; | ||||||
| import org.xml.sax.SAXException; | ||||||
|
|
||||||
| import java.io.IOException; | ||||||
| import java.net.MalformedURLException; | ||||||
| import java.net.URL; | ||||||
| import java.util.Arrays; | ||||||
| import java.util.List; | ||||||
| import java.util.stream.Collectors; | ||||||
|
|
||||||
| import static org.junit.Assert.*; | ||||||
|
|
||||||
| public class TestResultVisualizationIT { | ||||||
| private static JenkinsRule.WebClient jenkinsWebClient; | ||||||
|
|
||||||
| @Rule | ||||||
| public JenkinsRule jenkins = new JenkinsRule(); | ||||||
|
|
||||||
|
|
||||||
| @BeforeClass | ||||||
| public static void checkMatlabRoot() { | ||||||
| // Check if the MATLAB_ROOT environment variable is defined | ||||||
| String matlabRoot = System.getenv("MATLAB_ROOT"); | ||||||
| Assume.assumeTrue("Not running tests as MATLAB_ROOT environment variable is not defined", matlabRoot != null && !matlabRoot.isEmpty()); | ||||||
| } | ||||||
|
|
||||||
| @Before | ||||||
| public void createJenkinsWebClient(){ | ||||||
| jenkinsWebClient = jenkins.createWebClient(); | ||||||
| } | ||||||
|
|
||||||
| // Verify test results are shown in summary | ||||||
| @Test | ||||||
| public void verifyTestResultsSummary() throws Exception { | ||||||
| FreeStyleProject project = jenkins.createFreeStyleProject(); | ||||||
| project.setScm(new ExtractResourceSCM(Utilities.getRunMATLABTestsData())); | ||||||
|
|
||||||
| UseMatlabVersionBuildWrapper buildWrapper = new UseMatlabVersionBuildWrapper(); | ||||||
| buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), Utilities.getMatlabRoot())); | ||||||
| project.getBuildWrappersList().add(buildWrapper); | ||||||
|
|
||||||
| // Run tests through Run Command step | ||||||
| RunMatlabCommandBuilder scriptBuilder = new RunMatlabCommandBuilder(); | ||||||
| scriptBuilder.setMatlabCommand("runtests('IncludeSubfolders', true)"); | ||||||
| project.getBuildersList().add(scriptBuilder); | ||||||
|
|
||||||
| // Run tests through Run Build step | ||||||
| RunMatlabBuildBuilder buildtoolBuilder = new RunMatlabBuildBuilder(); | ||||||
| buildtoolBuilder.setTasks("test"); | ||||||
| project.getBuildersList().add(buildtoolBuilder); | ||||||
|
|
||||||
| FreeStyleBuild build = project.scheduleBuild2(0).get(); | ||||||
|
|
||||||
| // Verify MATLAB Test Result summary | ||||||
| String[] BuildResultSummary= getTestResultSummaryFromBuildStatusPage(build); | ||||||
Vahila marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| List.of(BuildResultSummary).forEach(summary -> { | ||||||
Vahila marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| assertTrue(summary.contains("Tests run: 4")); | ||||||
| assertTrue(summary.contains("Passed: 1")); | ||||||
| assertTrue(summary.contains("Failed: 3")); | ||||||
| assertTrue(summary.contains("Incomplete: 0")); | ||||||
| assertTrue(summary.contains("Not Run: 0")); | ||||||
| }); | ||||||
| } | ||||||
|
|
||||||
| @Test | ||||||
| public void verifyHyperlinkInSummary() throws Exception { | ||||||
| FreeStyleProject project = jenkins.createFreeStyleProject(); | ||||||
| project.setScm(new ExtractResourceSCM(Utilities.getRunMATLABTestsData())); | ||||||
|
|
||||||
| UseMatlabVersionBuildWrapper buildWrapper = new UseMatlabVersionBuildWrapper(); | ||||||
| buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), Utilities.getMatlabRoot())); | ||||||
| project.getBuildWrappersList().add(buildWrapper); | ||||||
|
|
||||||
| // Run tests through Run Build step | ||||||
| RunMatlabBuildBuilder buildtoolBuilder = new RunMatlabBuildBuilder(); | ||||||
| buildtoolBuilder.setTasks("test"); | ||||||
| project.getBuildersList().add(buildtoolBuilder); | ||||||
|
|
||||||
| FreeStyleBuild build = project.scheduleBuild2(0).get(); | ||||||
|
|
||||||
| String hyperlinkInSummary = getHyperlinkFromBuildStatus(build); | ||||||
|
|
||||||
| String hyperlinkOfTestResultsTab = getTestResultTabLinkFromSidePanel(build); | ||||||
|
|
||||||
| assertTrue(hyperlinkOfTestResultsTab.contains(hyperlinkInSummary)); | ||||||
| } | ||||||
|
|
||||||
| @Test | ||||||
| public void verifyContentInTestResultsTable() throws Exception{ | ||||||
| FreeStyleProject project = jenkins.createFreeStyleProject(); | ||||||
| project.setScm(new ExtractResourceSCM(Utilities.getRunMATLABTestsData())); | ||||||
|
|
||||||
| UseMatlabVersionBuildWrapper buildWrapper = new UseMatlabVersionBuildWrapper(); | ||||||
| buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), Utilities.getMatlabRoot())); | ||||||
| project.getBuildWrappersList().add(buildWrapper); | ||||||
|
|
||||||
| // Run tests through Run Build step | ||||||
| RunMatlabBuildBuilder buildtoolBuilder = new RunMatlabBuildBuilder(); | ||||||
| buildtoolBuilder.setTasks("test"); | ||||||
| project.getBuildersList().add(buildtoolBuilder); | ||||||
|
|
||||||
| FreeStyleBuild build = project.scheduleBuild2(0).get(); | ||||||
|
|
||||||
| // Verify button text | ||||||
| String totalTestsButtonText = getButtonText("TOTAL", build); | ||||||
| assertTrue(totalTestsButtonText.contains("4")); | ||||||
| assertTrue(totalTestsButtonText.contains("Total Tests")); | ||||||
|
|
||||||
| String passedButtonText = getButtonText("PASSED", build); | ||||||
| assertTrue(passedButtonText.contains("1")); | ||||||
| assertTrue(passedButtonText.contains("Passed")); | ||||||
|
|
||||||
| String failedButtonText = getButtonText("FAILED", build); | ||||||
| assertTrue(failedButtonText.contains("3")); | ||||||
| assertTrue(failedButtonText.contains("Failed")); | ||||||
|
|
||||||
| String incompleteButtonText = getButtonText("INCOMPLETE", build); | ||||||
| assertTrue(incompleteButtonText.contains("0")); | ||||||
| assertTrue(incompleteButtonText.contains("Incomplete")); | ||||||
|
|
||||||
| String notRunButtonText = getButtonText("NOT_RUN", build); | ||||||
| assertTrue(notRunButtonText.contains("0")); | ||||||
| assertTrue(notRunButtonText.contains("Not Run")); | ||||||
|
|
||||||
| // Verify the test filenames shown | ||||||
| String[] expectedTestFiles = {" testMultiply ", " squareTest ", " testSquare ", " testSum "}; | ||||||
| String[] testFiles = getTestFilesInTable(build); | ||||||
| assertEquals(testFiles, expectedTestFiles); | ||||||
|
|
||||||
| // Verify Diagnostics are shown for a failed test. | ||||||
| List<String[]> testsContentForAFile = getTestsInfoForATestFile("testMultiply", build); | ||||||
| assertEquals(testsContentForAFile.size(),1); | ||||||
| assertEquals(testsContentForAFile.get(0)[0].trim(), "testMultiplication"); // 'testMultiply has 'testMultiplication' test | ||||||
| assertNotNull(testsContentForAFile.get(0)[1]); // Diagnostics cant be null as 'testMultiply' fails | ||||||
| assertTrue(testsContentForAFile.get(0)[1].contains("testMultiply/testMultiplication")); | ||||||
| assertNotNull(testsContentForAFile.get(0)[2]); // Duration cannot be null | ||||||
|
|
||||||
| // Verify Diagnostics is empty for passed test | ||||||
| List<String[]> testsContent= getTestsInfoForATestFile("testSum", build); | ||||||
| assertEquals(testsContent.size(),1); | ||||||
| assertEquals(testsContent.get(0)[0].trim(), "testAddition"); // 'testSum has 'testAddition' test | ||||||
| assertEquals(testsContent.get(0)[1], ""); // No diagnostics as 'testAddition' passes | ||||||
| } | ||||||
|
|
||||||
| // Verify in matrix project | ||||||
| @Test | ||||||
| public void verifyTestResultsSummaryInMatrixProject() throws Exception { | ||||||
| String matlabRoot = System.getenv("MATLAB_ROOT"); | ||||||
| String matlabRoot22b = System.getenv("MATLAB_ROOT_22b"); | ||||||
| Assume.assumeTrue("Not running tests as MATLAB_ROOT_22b environment variable is not defined", matlabRoot22b != null && !matlabRoot22b.isEmpty()); | ||||||
|
|
||||||
| Utilities.setMatlabInstallation("MATLAB_PATH_1", matlabRoot, jenkins); | ||||||
| Utilities.setMatlabInstallation("MATLAB_PATH_22b", matlabRoot22b, jenkins); | ||||||
|
|
||||||
| MatrixProject matrixProject = jenkins.createProject(MatrixProject.class); | ||||||
| MatlabInstallationAxis MATLABAxis = new MatlabInstallationAxis(Arrays.asList("MATLAB_PATH_1", "MATLAB_PATH_22b")); | ||||||
| matrixProject.setAxes(new AxisList(MATLABAxis)); | ||||||
| matrixProject.setScm(new ExtractResourceSCM(Utilities.getRunMATLABTestsData())); | ||||||
|
|
||||||
| // Run tests through Run Build step | ||||||
| RunMatlabBuildBuilder buildtoolBuilder = new RunMatlabBuildBuilder(); | ||||||
| buildtoolBuilder.setTasks("test"); | ||||||
| matrixProject.getBuildersList().add(buildtoolBuilder); | ||||||
|
|
||||||
| MatrixBuild build = matrixProject.scheduleBuild2(0).get(); | ||||||
|
|
||||||
| Combination c = new Combination(new AxisList(new MatlabInstallationAxis(Arrays.asList("MATLAB_PATH_1"))), "MATLAB_PATH_1"); | ||||||
| MatrixRun run = build.getRun(c); | ||||||
| String[] buildResultSummary= getTestResultSummaryFromBuildStatusPage(run); | ||||||
|
||||||
| String[] buildResultSummary= getTestResultSummaryFromBuildStatusPage(run); | |
| String[] buildResultSummaries = getTestResultSummaryFromBuildStatusPage(run); |
Vahila marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Vahila marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the existing system test utilities right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, 'Utilities' is mainly used for system tests. I updated the method name to 'getURLForTestData' as it is more apt.