Library
Contents
Public
Documentation for TestReports.jl
's public interface.
TestReports.test
— FunctionTestReports.test(; kwargs...)
TestReports.test(pkg::Union{AbstractString, Vector{AbstractString}; kwargs...)
Keyword arguments:
coverage::Bool=false
: enable or disable generation of coverage statistics.julia_args::Union{Cmd, Vector{String}}
: options to be passed to the test process.test_args::Union{Cmd, Vector{String}}
: test arguments (ARGS
) available in the test process.logfilepath::AbstractString=pwd()
: file path where test reports are saved.logfilename::Union{AbstractString, Vector{AbstractString}}
: name(s) of test report file(s).
Generates a JUnit XML for the tests of package pkg
, or for the current project (which thus needs to be a package) if no positional argument is given to TestReports.test
. The test report is saved in the current working directory and called testlog.xml
if both logfilepath
and logfilename
are not supplied. If pkg
is of type Vector{String}
, the report filenames are prepended with the package name, for example Example_testlog.xml
.
If logfilename
is supplied, it must match the type (and length, if a vector) of pkg
.
The tests are run in the same way as Pkg.test
.
TestReports.recordproperty
— Functionrecordproperty(name::String, value)
Adds a property to a testset with name
and value
that will in turn be added to the <properties>
node of the corresponding testsuite in the JUnit XML.
Multiple properties can be added to one testset, but if the same property is set on both parent and child testsets, the value in the parent testset takes precedence over that in the child.
The suggested use of this function is to place it inside a testset with unspecified type (see Examples). This will ensure that Pkg.test
is unnaffected, but that the properties are added to the report when TestReports.test
is used. This is because TestReports
wraps package tests in a ReportingTestSet
, and the function only adds a property when it is within a ReportingTestSet
.
If a child testset is a ReportingTestSet
but its parent isn't, the property should be in the report when TestReport.test
is used, assuming that the parent testset type doesn't do anything to affect the reporting behaviour. However this is not tested functionality.
value
must be serializable by EzML, which gives quite a lot of freedom.
Examples
using TestReports
# Default testset used, so function will not affect Pkg.test but will be used when
# generating JUnit XML.
@testset "MyTestSet" begin
recordproperty("ID", 42)
recordproperty("File", @__FILE__)
recordproperty("Bool", true)
@test 1==1
@test 2==2
end
TestReports.ReportingTestSet
— TypeReportingTestSet
Custom AbstractTestSet
type designed to be used by TestReports.jl
for creation of JUnit XMLs.
Does not throw an error when a test fails or has an error. Upon finish
ing, a ReportingTestSet
will display the default test output, and then flatten to a structure that is suitable for report generation.
It is designed to be wrapped around a package's runtests.jl
file and this is assumed when both the test results are displayed and when the TestSet
is flatted upon finish
. See bin/reporttests.jl
for an example of this use. ReportingTestSet
s are not designed to be used directly in a package's tests, and this is not recommended or supported.
A ReportingTestSet
has the description
and results
fields as per a DefaultTestSet
, and has an additional properties
field which is used to record properties to be inserted into the report.
See also: flatten_results!
, recordproperty
, report
TestReports.any_problems
— Functionany_problems(ts)
Checks a testset to see if there were any problems (Error
s or Fail
s). Note that unlike the DefaultTestSet
, the ReportingTestSet
does not throw an exception on a failure. Thus to set the exit code from the runner code, we check it using exit(any_problems(top_level_testset))
.
TestReports.report
— Functionreport(ts::AbstractTestSet)
Will produce an XMLDocument
that contains a report about the TestSet
's results. This report will follow the JUnit XML schema.
In theory this works on many kinds of TestSet
s, but it is primarily intended for use on ReportingTestSet
s. To report correctly, the TestSet
must have the following structure:
AbstractTestSet
└─ AbstractTestSet
└─ Result
That is, the results of the top level TestSet
must all be AbstractTestSet
s, and the results of those TestSet
s must all be Results
.
Private
Package internals documentation.
Report Generation
TestReports.checkinstalled!
— Functioncheckinstalled!(ctx::Union{Context, EnvCache}, pkgspec::Types.PackageSpec)
Checks if the package is installed by using ensure_resolved
from Pkg/src/Types.jl
. This function fails if the package is not installed, but here we wrap it in a try-catch as we may want to test another package after the one that isn't installed.
For Julia versions V1.4 and later, the first arguments of the Pkg functions used is of type Pkg.Types.Context
. For earlier versions, they are of type Pkg.Types.EnvCache
.
TestReports.gettestfilepath
— Functiongettestfilepath(ctx::Context, pkgspec::Types.PackageSpec)
Gets the testfile path of the package. Code for each Julia version mirrors that found in Pkg\src\Operations.jl
.
TestSets
TestReports._flatten_results!
— Method_flatten_results!(ts::AbstractTestSet)::Vector{<:AbstractTestSet}
Recursively flatten ts
to a vector of TestSet
s.
TestReports._flatten_results!
— Method_flatten_results!(rs::Result)
Return vector containing rs
so that when iterated through, rs
is added to the results vector.
TestReports.add_to_ts_default!
— Methodadd_to_ts_default!(ts_default::DefaultTestSet, result::Result)
add_to_ts_default!(ts_default::DefaultTestSet, ts::AbstractTestSet)
add_to_ts_default!(ts_default::DefaultTestSet, ts::ReportingTestSet)
Populate ts_default
with the supplied variable. If the variable is a Result
or an AbstractTestSet
(but not a ReportingTestSet
) then it is record
ed. If it is a ReportingTestSet
then a new DefaultTestSet
with matching description is created, populated by recursively calling this function and then added to the results of ts_default
.
TestReports.display_reporting_testset
— Methoddisplay_reporting_testset(ts::ReportingTestSet)
Displays the test output in the same format as Pkg.test
by using a DefaultTestSet
.
TestReports.flatten_results!
— Methodflatten_results!(ts::AbstractTestSet)
Returns a flat structure 3 deep, of TestSet
-> TestSet
-> Result
. This is necessary for writing a report, as a JUnit XML does not allow one testsuite to be nested in another. The top level TestSet
becomes the testsuites element, and the middle level TestSet
s become individual testsuite elements, and the Result
s become the testcase elements.
If ts.results
contains any Result
s, these are added into a new TestSet
with the description "Top level tests", which then replaces them in ts.results
.
TestReports.handle_top_level_results!
— Methodhandle_top_level_results!(ts::AbstractTestSet)
If ts.results
contains any Result
s, these are removed from ts.results
and added to a new ReportingTestSet
, which in turn is added to ts.results
. This leaves ts.results
only containing AbstractTestSet
s.
TestReports.update_testset_properties!
— Methodupdate_testset_properties!(childts::AbstractTestSet, ts::AbstractTestSet)
update_testset_properties!(childts::ReportingTestSet, ts::ReportingTestSet)
Adds properties of ts
to childts
. If any properties being added already exist in childts
, a warning is displayed and the value in ts
is overwritten.
If ts
and\or childts
is not a ReportingTestSet
, this is handled in the AbstractTestSet
method:
- If
ts
is not aReportingTestSet
, it has no properties to add tochildts
and therefore nothing happens. - If
childts
is not aReportingTestSet
andts
has properties, then a warning is shown.
XML Writing
TestReports.add_testsuite_properties!
— Methodadd_testsuite_properties!(x_testsuite, ts::ReportingTestSet)
Add all key value pairs in the properties
field of a ReportingTestSet
to the corresponding testsuite xml element.
TestReports.check_ts_structure
— Methodcheck_ts_structure(ts::AbstractTestSet)
Throws an exception if ts
does not have the right structure for report
.
See also: report
TestReports.error_xml
— Methodfailure_xml(message, test_type, content)
Create an error node (which will be the child of a testcase).
TestReports.failure_xml
— Methodfailure_xml(message, test_type, content)
Create a failure node (which will be the child of a testcase).
TestReports.get_error_info
— Methodget_error_info(v::Error)
Return message and type of error for testcase attribute. Uses test_type
field to determine what caused the original error.
TestReports.get_failure_message
— Methodgetfailuremessage(v::Fail)
Return message for failed test testcase attribute. Uses test_type
field to determine what caused the original failure.
TestReports.set_attribute!
— Methodset_attribute!(node, attr, val)
Add the attritube with name attr
and value val
to node
.
TestReports.skip_xml
— Methodskip_xml()
Create a skip node (which will be the child of a testcase).
TestReports.testcase_xml
— Methodtestcase_xml(name, id, x_children)
Create a testcase element of a JUnit XML.
This is the generic form (with name, id and children) that is used by other methods.
TestReports.testcase_xml
— Methodtestcase_xml(v::Result, childs)
Create a testcase element of a JUnit XML for the result v
.
The original expression of the test is used as the name, whilst the id is defaulted to testcaseid_.
TestReports.testsuite_xml
— Methodtestsuite_xml(name, id, ntests, nfails, nerrors, x_children)
Create a testsuite element of a JUnit XML.
TestReports.testsuites_xml
— Methodtestsuites_xml(name, id, ntests, nfails, nerrors, x_children)
Create the testsuites element of a JUnit XML.
TestReports.to_xml
— Methodto_xml(ts::AbstractTestSet)
Create a testsuite node from an AbstractTestSet
, by creating nodes for each result in ts.results
. For creating a JUnit XML, all results must be Result
s, that is they cannot be AbstractTestSet
s, as the XML cannot have one testsuite nested inside another.
TestReports.to_xml
— Methodto_xml(res::Pass)
to_xml(res::Fail)
to_xml(res::Broken)
to_xml(res::Error)
Create a testcase node from the result and return it along with information on number of tests.
Index
TestReports.ReportingTestSet
TestReports._flatten_results!
TestReports._flatten_results!
TestReports.add_testsuite_properties!
TestReports.add_to_ts_default!
TestReports.any_problems
TestReports.check_ts_structure
TestReports.checkinstalled!
TestReports.display_reporting_testset
TestReports.error_xml
TestReports.failure_xml
TestReports.flatten_results!
TestReports.get_error_info
TestReports.get_failure_message
TestReports.gettestfilepath
TestReports.handle_top_level_results!
TestReports.recordproperty
TestReports.report
TestReports.set_attribute!
TestReports.skip_xml
TestReports.test
TestReports.testcase_xml
TestReports.testcase_xml
TestReports.testsuite_xml
TestReports.testsuites_xml
TestReports.to_xml
TestReports.to_xml
TestReports.update_testset_properties!