Package hudson.tasks.junit
Class TestResult
-
- All Implemented Interfaces:
ModelObject
,SearchableModelObject
,SearchItem
,Serializable
public final class TestResult extends MetaTabulatedResult
Root of all the test results for one build.- Author:
- Kohsuke Kawaguchi
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static long
FILE_TIME_PRECISION_MARGIN
-
Fields inherited from class hudson.tasks.test.TabulatedResult
testsByBlock
-
-
Constructor Summary
Constructors Constructor Description TestResult()
Creates an empty result.TestResult(boolean keepLongStdio)
TestResult(long filesTimestamp, org.apache.tools.ant.DirectoryScanner results)
Deprecated.TestResult(long filesTimestamp, org.apache.tools.ant.DirectoryScanner results, boolean keepLongStdio)
Deprecated.TestResult(long filesTimestamp, org.apache.tools.ant.DirectoryScanner results, boolean keepLongStdio, boolean keepProperties, PipelineTestDetails pipelineTestDetails, boolean skipOldReports)
Collect reports from the givenDirectoryScanner
, while filtering out all files that were created before the given time.TestResult(long filesTimestamp, org.apache.tools.ant.DirectoryScanner results, boolean keepLongStdio, PipelineTestDetails pipelineTestDetails)
Deprecated.TestResult(TestResultImpl impl)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description TabulatedResult
blockToTestResult(PipelineBlockWithTests block, TabulatedResult fullResult)
Get an aggregatedTestResult
for all test results in aPipelineBlockWithTests
and any children it may have.PackageResult
byPackage(String packageName)
TestResult
findCorrespondingResult(String id)
Find the test result corresponding to the one identified byid
within this test result.void
freeze(TestResultAction parent)
Builds up the transient part of the data structure from resultsparsed
so far.CaseResult
getCase(String suiteName, String transformedFullDisplayName)
Collection<PackageResult>
getChildren()
Gets the child test result objects.String
getChildTitle()
String
getChildType()
Get a simple name for the type of children theTabulatedResult.getChildren()
method returns, for example "case", "class" or "package".String
getDisplayName()
float
getDuration()
Time it took to run this test.Object
getDynamic(String token, org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)
String
getErrorDetails()
If there was an error or a failure, this is the text from the message.String
getErrorStackTrace()
If there was an error or a failure, this is the stack trace, or otherwise null.int
getFailCount()
Gets the total number of failed tests.int
getFailedSince()
If this test failed, then return the build number when this test started failing.Run<?,?>
getFailedSinceRun()
If this test failed, then return the run when this test started failing.List<CaseResult>
getFailedTests()
All failed tests.String
getName()
Gets the name of this object.TestObject
getParent()
Reverse pointer ofTabulatedResult.getChildren()
.AbstractTestResultAction
getParentAction()
Returns the action that points to the top level test result includes this test result.int
getPassCount()
Gets the total number of passed tests.List<CaseResult>
getPassedTests()
Gets the "children" of this test result that passedTestResultImpl
getPluggableStorage()
TestResult
getPreviousResult()
Gets the counter part of thisTestResult
in the previous run.Map<String,String>
getProperties()
TestResult
getResultByNode(String nodeId)
TestResult
getResultByNodes(List<String> nodeIds)
TestResult
getResultForPipelineBlock(String blockId)
Run<?,?>
getRun()
int
getSkipCount()
Gets the total number of skipped tests.List<CaseResult>
getSkippedTests()
Gets the "children" of this test result that were skippedString
getStderr()
The stderr of this test.String
getStdout()
The stdout of this test.SuiteResult
getSuite(String name)
Returns the first suite with the given name.Collection<SuiteResult>
getSuites()
Collection<SuiteResult>
getSuites(String name)
Returns all suites with the given name.TestResult
getTestResult()
Returns the top level test result data.String
getTitle()
Gets the human readable title of this result object.int
getTotalCount()
Gets the total number of tests.boolean
hasChildren()
Whether this test result has children.boolean
isEmpty()
Returnstrue
if this doesn't have any any test results.boolean
isPassed()
boolean
isSkipOldReports()
void
parse(long filesTimestamp, File baseDir, PipelineTestDetails pipelineTestDetails, String[] reportFiles)
Collect reports from the given report files, while filtering out all files that were created before the given time.void
parse(long filesTimestamp, File baseDir, String[] reportFiles)
Deprecated.void
parse(long filesTimestamp, Iterable<File> reportFiles)
Deprecated.void
parse(long filesTimestamp, Iterable<File> reportFiles, PipelineTestDetails pipelineTestDetails)
Collect reports from the given report filesvoid
parse(long filesTimestamp, org.apache.tools.ant.DirectoryScanner results)
Deprecated.void
parse(long filesTimestamp, org.apache.tools.ant.DirectoryScanner results, PipelineTestDetails pipelineTestDetails)
Collect reports from the givenDirectoryScanner
, while filtering out all files that were created before the given time.void
parse(File reportFile)
Deprecated.void
parse(File reportFile, PipelineTestDetails pipelineTestDetails)
Parses an additional report file.void
parse(Iterable<File> reportFiles, PipelineTestDetails pipelineTestDetails)
Deprecated.void
setParent(TestObject parent)
Sets the parent test resultvoid
setParentAction(AbstractTestResultAction action)
If the concept of a parent action is important to a subclass, then it should provide a non-noop implementation of this method.void
setSkipOldReports(boolean skipOldReports)
void
tally()
Recount my children.-
Methods inherited from class hudson.tasks.test.TabulatedResult
getPipelineBlockWithTests, hasMultipleBlocks, populateBlocks
-
Methods inherited from class hudson.tasks.test.TestResult
annotate, getBuildResult, getResultInRun, toPrettyString
-
Methods inherited from class hudson.tasks.test.TestObject
doSubmitDescription, getApi, getDescription, getDurationString, getFullDisplayName, getFullName, getHistory, getId, getRelativePathFrom, getResultInBuild, getSafeName, getSearchUrl, getTestAction, getTestActions, getTestResultAction, getTopLevelTestResult, getUrl, safe, setDescription, uniquifyName
-
Methods inherited from class hudson.tasks.junit.TestObject
getOwner
-
Methods inherited from class hudson.model.AbstractModelObject
getSearch, getSearchIndex, getSearchName, makeSearchIndex, requirePOST, sendError, sendError, sendError, sendError, sendError
-
-
-
-
Constructor Detail
-
TestResult
public TestResult()
Creates an empty result.
-
TestResult
public TestResult(boolean keepLongStdio)
- Since:
- 1.522
-
TestResult
@Deprecated public TestResult(long filesTimestamp, org.apache.tools.ant.DirectoryScanner results) throws IOException
Deprecated.- Throws:
IOException
-
TestResult
@Deprecated public TestResult(long filesTimestamp, org.apache.tools.ant.DirectoryScanner results, boolean keepLongStdio) throws IOException
Deprecated.- Throws:
IOException
-
TestResult
@Deprecated public TestResult(long filesTimestamp, org.apache.tools.ant.DirectoryScanner results, boolean keepLongStdio, PipelineTestDetails pipelineTestDetails) throws IOException
Deprecated.- Throws:
IOException
-
TestResult
public TestResult(long filesTimestamp, org.apache.tools.ant.DirectoryScanner results, boolean keepLongStdio, boolean keepProperties, PipelineTestDetails pipelineTestDetails, boolean skipOldReports) throws IOException
Collect reports from the givenDirectoryScanner
, while filtering out all files that were created before the given time.- Parameters:
filesTimestamp
- per default files older than this will be ignored (depending on param skipOldReports)keepLongStdio
- if true, retain a suite's complete stdout/stderr even if this is huge and the suite passedpipelineTestDetails
- APipelineTestDetails
instance containing Pipeline-related additional arguments.skipOldReports
- to parse or not test files older than filesTimestamp- Throws:
IOException
- Since:
- 1.22
-
TestResult
public TestResult(TestResultImpl impl)
-
-
Method Detail
-
getPluggableStorage
@CheckForNull public TestResultImpl getPluggableStorage()
-
getParent
public TestObject getParent()
Description copied from class:TestObject
Reverse pointer ofTabulatedResult.getChildren()
.- Specified by:
getParent
in classTestObject
- Returns:
- the parent
TestObject
.
-
setParent
public void setParent(TestObject parent)
Description copied from class:TestResult
Sets the parent test result- Overrides:
setParent
in classTestResult
- Parameters:
parent
- Parent test result.
-
getTestResult
public TestResult getTestResult()
Description copied from class:TestObject
Returns the top level test result data.- Overrides:
getTestResult
in classTestObject
-
parse
@Deprecated public void parse(long filesTimestamp, org.apache.tools.ant.DirectoryScanner results) throws IOException
Deprecated.- Throws:
IOException
-
parse
public void parse(long filesTimestamp, org.apache.tools.ant.DirectoryScanner results, PipelineTestDetails pipelineTestDetails) throws IOException
Collect reports from the givenDirectoryScanner
, while filtering out all files that were created before the given time.- Parameters:
filesTimestamp
- file timestamp to filter files older.results
- Directory scanner.pipelineTestDetails
- APipelineTestDetails
instance containing Pipeline-related additional arguments.- Throws:
IOException
- if an error occurs.- Since:
- 1.22
-
parse
@Deprecated public void parse(long filesTimestamp, File baseDir, String[] reportFiles) throws IOException
Deprecated.- Throws:
IOException
-
parse
public void parse(long filesTimestamp, File baseDir, PipelineTestDetails pipelineTestDetails, String[] reportFiles) throws IOException
Collect reports from the given report files, while filtering out all files that were created before the given time.- Parameters:
filesTimestamp
- file timestamp to filter files older.baseDir
- Base directory.pipelineTestDetails
- APipelineTestDetails
instance containing Pipeline-related additional arguments.reportFiles
- Report files.- Throws:
IOException
- if an error occurs.- Since:
- 1.22
-
getPreviousResult
public TestResult getPreviousResult()
Description copied from class:TestResult
Gets the counter part of thisTestResult
in the previous run.- Overrides:
getPreviousResult
in classTestResult
- Returns:
- null if no such counter part exists.
-
parse
@Deprecated public void parse(long filesTimestamp, Iterable<File> reportFiles) throws IOException
Deprecated.- Throws:
IOException
-
parse
public void parse(long filesTimestamp, Iterable<File> reportFiles, PipelineTestDetails pipelineTestDetails) throws IOException
Collect reports from the given report files- Parameters:
filesTimestamp
- Build time.reportFiles
- Report files.pipelineTestDetails
- APipelineTestDetails
instance containing Pipeline-related additional arguments.- Throws:
IOException
- if an error occurs.- Since:
- 1.22
-
parse
@Deprecated public void parse(Iterable<File> reportFiles, PipelineTestDetails pipelineTestDetails) throws IOException
Deprecated.Collect reports from the given report files- Parameters:
reportFiles
- Report files.pipelineTestDetails
- APipelineTestDetails
instance containing Pipeline-related additional arguments.- Throws:
IOException
- if an error occurs.
-
parse
@Deprecated public void parse(File reportFile) throws IOException
Deprecated.- Throws:
IOException
-
parse
public void parse(File reportFile, PipelineTestDetails pipelineTestDetails) throws IOException
Parses an additional report file.- Parameters:
reportFile
- Report file to parse.pipelineTestDetails
- APipelineTestDetails
instance containing Pipeline-related additional arguments.- Throws:
IOException
- if an error occurs.- Since:
- 1.22
-
getDisplayName
public String getDisplayName()
-
getRun
public Run<?,?> getRun()
- Overrides:
getRun
in classTestObject
- Returns:
- the run in which this test was executed.
-
findCorrespondingResult
public TestResult findCorrespondingResult(String id)
Description copied from class:TestObject
Find the test result corresponding to the one identified byid
within this test result.- Specified by:
findCorrespondingResult
in classTestObject
- Parameters:
id
- The path to the original test result- Returns:
- A corresponding test result, or null if there is no corresponding result.
-
getTitle
public String getTitle()
Description copied from class:TestResult
Gets the human readable title of this result object.- Overrides:
getTitle
in classTestResult
- Returns:
- the human readable title of this result object.
-
getChildTitle
public String getChildTitle()
- Overrides:
getChildTitle
in classTabulatedResult
-
getChildType
public String getChildType()
Description copied from class:TabulatedResult
Get a simple name for the type of children theTabulatedResult.getChildren()
method returns, for example "case", "class" or "package".- Overrides:
getChildType
in classTabulatedResult
- Returns:
- the type of children this result has, all lowercase.
-
getDuration
@Exported(visibility=999) public float getDuration()
Description copied from class:TestResult
Time it took to run this test. In seconds.- Overrides:
getDuration
in classTestResult
- Returns:
- the time in seconds the test ran.
-
getPassCount
@Exported(visibility=999) public int getPassCount()
Description copied from class:TestResult
Gets the total number of passed tests.- Overrides:
getPassCount
in classTestResult
- Returns:
- the total number of passed tests.
-
getFailCount
@Exported(visibility=999) public int getFailCount()
Description copied from class:TestResult
Gets the total number of failed tests.- Overrides:
getFailCount
in classTestResult
- Returns:
- the total number of failed tests.
-
getSkipCount
@Exported(visibility=999) public int getSkipCount()
Description copied from class:TestResult
Gets the total number of skipped tests.- Overrides:
getSkipCount
in classTestResult
- Returns:
- the total number of skipped tests.
-
getTotalCount
public int getTotalCount()
Description copied from class:TestObject
Gets the total number of tests.- Overrides:
getTotalCount
in classTestObject
- Returns:
- the total number of tests.
-
isEmpty
@Exported(visibility=999) public boolean isEmpty()
Returnstrue
if this doesn't have any any test results.- Returns:
- whether this doesn't contain any test results.
- Since:
- 1.511
-
getFailedTests
public List<CaseResult> getFailedTests()
Description copied from class:MetaTabulatedResult
All failed tests.- Specified by:
getFailedTests
in classMetaTabulatedResult
- Returns:
- the children of this test result, if any, or an empty collection
-
getPassedTests
public List<CaseResult> getPassedTests()
Gets the "children" of this test result that passed- Overrides:
getPassedTests
in classTestResult
- Returns:
- the children of this test result, if any, or an empty collection
-
getSkippedTests
public List<CaseResult> getSkippedTests()
Gets the "children" of this test result that were skipped- Overrides:
getSkippedTests
in classTestResult
- Returns:
- the children of this test result, if any, or an empty list
-
getFailedSince
public int getFailedSince()
If this test failed, then return the build number when this test started failing.- Overrides:
getFailedSince
in classTestResult
- Returns:
- the build number when this test started failing.
-
getFailedSinceRun
public Run<?,?> getFailedSinceRun()
If this test failed, then return the run when this test started failing.- Overrides:
getFailedSinceRun
in classTestResult
- Returns:
- the run when this test started failing.
-
getStdout
public String getStdout()
The stdout of this test.Depending on the tool that produced the XML report, this method works somewhat inconsistently. With some tools (such as Maven surefire plugin), you get the accurate information, that is the stdout from this test case. With some other tools (such as the JUnit task in Ant), this method returns the stdout produced by the entire test suite.
If you need to know which is the case, compare this output fromSuiteResult.getStdout()
.- Overrides:
getStdout
in classTestResult
- Returns:
- the stdout of this test.
- Since:
- 1.294
-
getStderr
public String getStderr()
The stderr of this test.- Overrides:
getStderr
in classTestResult
- Returns:
- the stderr of this test.
- Since:
- 1.294
- See Also:
getStdout()
-
getProperties
public Map<String,String> getProperties()
- Overrides:
getProperties
in classTestResult
-
getErrorStackTrace
public String getErrorStackTrace()
If there was an error or a failure, this is the stack trace, or otherwise null.- Overrides:
getErrorStackTrace
in classTestResult
- Returns:
- the stack trace of the error or failure.
-
getErrorDetails
public String getErrorDetails()
If there was an error or a failure, this is the text from the message.- Overrides:
getErrorDetails
in classTestResult
- Returns:
- the message of the error or failure.
-
isPassed
public boolean isPassed()
- Overrides:
isPassed
in classTestResult
- Returns:
- true if the test was not skipped and did not fail, false otherwise.
-
getChildren
public Collection<PackageResult> getChildren()
Description copied from class:TabulatedResult
Gets the child test result objects.- Specified by:
getChildren
in classTabulatedResult
- Returns:
- the child test result objects.
- See Also:
TestObject.getParent()
-
hasChildren
public boolean hasChildren()
Whether this test result has children.- Specified by:
hasChildren
in classTabulatedResult
-
getSuites
@Exported(inline=true, visibility=9) public Collection<SuiteResult> getSuites()
-
getName
public String getName()
Description copied from class:TestObject
Gets the name of this object.- Overrides:
getName
in classTestObject
- Returns:
- the name of this object.
-
getDynamic
public Object getDynamic(String token, org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)
- Overrides:
getDynamic
in classTestObject
-
byPackage
public PackageResult byPackage(String packageName)
-
getSuite
@CheckForNull public SuiteResult getSuite(String name)
Returns the first suite with the given name. Prefer usinggetSuites(String)
to disambiguate suites with the same name.- Parameters:
name
- the suite name- Returns:
- The first test suite with the given name, or null if not found.
-
getSuites
@NonNull public Collection<SuiteResult> getSuites(String name)
Returns all suites with the given name.- Parameters:
name
- the suite name- Returns:
- all suites with the given name
-
getResultByNode
@NonNull public TestResult getResultByNode(@NonNull String nodeId)
-
getResultByNodes
@NonNull public TestResult getResultByNodes(@NonNull List<String> nodeIds)
-
setParentAction
public void setParentAction(AbstractTestResultAction action)
Description copied from class:TestResult
If the concept of a parent action is important to a subclass, then it should provide a non-noop implementation of this method.- Overrides:
setParentAction
in classTestResult
- Parameters:
action
- Action that points to the top level test result.
-
getParentAction
public AbstractTestResultAction getParentAction()
Description copied from class:TestResult
Returns the action that points to the top level test result includes this test result.- Overrides:
getParentAction
in classTestResult
- Returns:
- action The action that points to the top level test result.
-
tally
public void tally()
Recount my children.- Overrides:
tally
in classTestResult
-
freeze
public void freeze(TestResultAction parent)
Builds up the transient part of the data structure from resultsparsed
so far.After the data is frozen, more files can be parsed and then freeze can be called again.
-
getResultForPipelineBlock
@NonNull public TestResult getResultForPipelineBlock(@NonNull String blockId)
-
isSkipOldReports
public boolean isSkipOldReports()
-
setSkipOldReports
public void setSkipOldReports(boolean skipOldReports)
-
blockToTestResult
@NonNull public TabulatedResult blockToTestResult(@NonNull PipelineBlockWithTests block, @NonNull TabulatedResult fullResult)
Get an aggregatedTestResult
for all test results in aPipelineBlockWithTests
and any children it may have.- Overrides:
blockToTestResult
in classTabulatedResult
-
getCase
public CaseResult getCase(String suiteName, String transformedFullDisplayName)
-
-