mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Cleanup JUnit test case hierarchy
This commit is contained in:
parent
3776cd917e
commit
93368503e6
7 changed files with 125 additions and 81 deletions
|
@ -1,26 +1,19 @@
|
||||||
|
require "./failure_junit_test_case"
|
||||||
|
|
||||||
module Spectator::Formatting
|
module Spectator::Formatting
|
||||||
private struct ErrorJUnitTestCase
|
# JUnit test case for a errored result.
|
||||||
|
private class ErrorJUnitTestCase < FailureJUnitTestCase
|
||||||
|
# Result for this test case.
|
||||||
|
private getter result
|
||||||
|
|
||||||
|
# Creates the JUnit test case.
|
||||||
def initialize(@result : ErroredResult)
|
def initialize(@result : ErroredResult)
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_xml(xml : ::XML::Builder)
|
# Adds the exception to the XML block.
|
||||||
xml.element("testcase",
|
private def content(xml)
|
||||||
name: @result.example,
|
|
||||||
status: @result,
|
|
||||||
time: @result.elapsed.total_seconds,
|
|
||||||
classname: classname,
|
|
||||||
assertions: @result.expectations.size) do
|
|
||||||
xml.element("error", message: @result.error.message, type: @result.error.class)
|
xml.element("error", message: @result.error.message, type: @result.error.class)
|
||||||
@result.expectations.each_unsatisfied do |expectation|
|
super
|
||||||
xml.element("failure", message: expectation.actual_message) do
|
|
||||||
# TODO: Add values as text to this block.
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
private def classname
|
|
||||||
"TODO"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,15 +1,18 @@
|
||||||
|
require "./finished_junit_test_case"
|
||||||
|
|
||||||
module Spectator::Formatting
|
module Spectator::Formatting
|
||||||
private struct FailureJUnitTestCase
|
# JUnit test case for a failed result.
|
||||||
|
private class FailureJUnitTestCase < FinishedJUnitTestCase
|
||||||
|
# Result for this test case.
|
||||||
|
private getter result
|
||||||
|
|
||||||
|
# Creates the JUnit test case.
|
||||||
def initialize(@result : FailedResult)
|
def initialize(@result : FailedResult)
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_xml(xml : ::XML::Builder)
|
# Adds the failed expectations to the XML block.
|
||||||
xml.element("testcase",
|
private def content(xml)
|
||||||
name: @result.example,
|
super
|
||||||
status: @result,
|
|
||||||
time: @result.elapsed.total_seconds,
|
|
||||||
classname: classname,
|
|
||||||
assertions: @result.expectations.size) do
|
|
||||||
@result.expectations.each_unsatisfied do |expectation|
|
@result.expectations.each_unsatisfied do |expectation|
|
||||||
xml.element("failure", message: expectation.actual_message) do
|
xml.element("failure", message: expectation.actual_message) do
|
||||||
# TODO: Add values as text to block.
|
# TODO: Add values as text to block.
|
||||||
|
@ -17,9 +20,4 @@ module Spectator::Formatting
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private def classname
|
|
||||||
"TODO"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
21
src/spectator/formatting/finished_junit_test_case.cr
Normal file
21
src/spectator/formatting/finished_junit_test_case.cr
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
require "./junit_test_case"
|
||||||
|
|
||||||
|
module Spectator::Formatting
|
||||||
|
# Commonalities of all test cases that ran (success or failure).
|
||||||
|
private abstract class FinishedJUnitTestCase < JUnitTestCase
|
||||||
|
# Produces the test case XML element.
|
||||||
|
def to_xml(xml : ::XML::Builder)
|
||||||
|
xml.element("testcase", **full_attributes) do
|
||||||
|
content(xml)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Attributes that go in the "testcase" XML element.
|
||||||
|
private def full_attributes
|
||||||
|
attributes.merge(
|
||||||
|
time: result.elapsed.total_seconds,
|
||||||
|
assertions: result.expectations.size
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,26 +1,34 @@
|
||||||
module Spectator::Formatting
|
module Spectator::Formatting
|
||||||
# Selector for creating a JUnit test case based on a result.
|
# Base type for all JUnit test case results.
|
||||||
private module JUnitTestCase
|
private abstract class JUnitTestCase
|
||||||
extend self
|
# Produces the test case XML element.
|
||||||
|
def to_xml(xml : ::XML::Builder)
|
||||||
# Creates a successful JUnit test case.
|
xml.element("testcase", **attributes) do
|
||||||
def success(result)
|
content(xml)
|
||||||
SuccessfulJUnitTestCase.new(result.as(SuccessfulResult))
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Creates a failure JUnit test case.
|
# Attributes that go in the "testcase" XML element.
|
||||||
def failure(result)
|
private def attributes
|
||||||
FailureJUnitTestCase.new(result.as(FailedResult))
|
{
|
||||||
|
name: result.example,
|
||||||
|
status: result,
|
||||||
|
classname: classname,
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
# Creates an error JUnit test case.
|
# Result to pull values from.
|
||||||
def error(result)
|
private abstract def result
|
||||||
ErrorJUnitTestCase.new(result.as(ErroredResult))
|
|
||||||
|
# Adds additional content to the "testcase" XML block.
|
||||||
|
# Override this to add more content.
|
||||||
|
private def content(xml)
|
||||||
|
# ...
|
||||||
end
|
end
|
||||||
|
|
||||||
# Creates a skipped JUnit test case.
|
# Java-ified class name created from the spec.
|
||||||
def pending(result)
|
private def classname
|
||||||
SkippedJUnitTestCase.new(result.as(PendingResult))
|
"TODO"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -18,19 +18,51 @@ module Spectator::Formatting
|
||||||
time: @report.runtime.total_seconds,
|
time: @report.runtime.total_seconds,
|
||||||
name: name,
|
name: name,
|
||||||
package: package) do
|
package: package) do
|
||||||
@report.each do |result|
|
add_test_cases(xml)
|
||||||
test_case = result.call(JUnitTestCase) { |r| r }
|
|
||||||
test_case.to_xml(xml)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Adds the test case elements to the XML.
|
||||||
|
private def add_test_cases(xml)
|
||||||
|
@report.each do |result|
|
||||||
|
test_case = result.call(JUnitTestCaseSelector) { |r| r }
|
||||||
|
test_case.to_xml(xml)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Java-ified name of the test suite.
|
||||||
private def name
|
private def name
|
||||||
"TODO"
|
"TODO"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Java-ified package (path) of the test suite.
|
||||||
private def package
|
private def package
|
||||||
"TODO"
|
"TODO"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Selector for creating a JUnit test case based on a result.
|
||||||
|
private module JUnitTestCaseSelector
|
||||||
|
extend self
|
||||||
|
|
||||||
|
# Creates a successful JUnit test case.
|
||||||
|
def success(result)
|
||||||
|
SuccessfulJUnitTestCase.new(result.as(SuccessfulResult))
|
||||||
|
end
|
||||||
|
|
||||||
|
# Creates a failure JUnit test case.
|
||||||
|
def failure(result)
|
||||||
|
FailureJUnitTestCase.new(result.as(FailedResult))
|
||||||
|
end
|
||||||
|
|
||||||
|
# Creates an error JUnit test case.
|
||||||
|
def error(result)
|
||||||
|
ErrorJUnitTestCase.new(result.as(ErroredResult))
|
||||||
|
end
|
||||||
|
|
||||||
|
# Creates a skipped JUnit test case.
|
||||||
|
def pending(result)
|
||||||
|
SkippedJUnitTestCase.new(result.as(PendingResult))
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
|
require "./junit_test_case"
|
||||||
|
|
||||||
module Spectator::Formatting
|
module Spectator::Formatting
|
||||||
private struct SkippedJUnitTestCase
|
# JUnit test case for a pending result.
|
||||||
|
private class SkippedJUnitTestCase < JUnitTestCase
|
||||||
|
# Result for this test case.
|
||||||
|
private getter result
|
||||||
|
|
||||||
|
# Creates the JUnit test case.
|
||||||
def initialize(@result : PendingResult)
|
def initialize(@result : PendingResult)
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_xml(xml : ::XML::Builder)
|
# Adds the skipped tag to the XML block.
|
||||||
xml.element("testcase",
|
private def content(xml)
|
||||||
name: @result.example,
|
super
|
||||||
status: @result,
|
|
||||||
classname: classname) do
|
|
||||||
xml.element("skipped")
|
xml.element("skipped")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private def classname
|
|
||||||
"TODO"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,19 +1,11 @@
|
||||||
module Spectator::Formatting
|
module Spectator::Formatting
|
||||||
private struct SuccessfulJUnitTestCase
|
# JUnit test case for a successful result.
|
||||||
|
private class SuccessfulJUnitTestCase < FinishedJUnitTestCase
|
||||||
|
# Result for this test case.
|
||||||
|
private getter result
|
||||||
|
|
||||||
|
# Creates the JUnit test case.
|
||||||
def initialize(@result : SuccessfulResult)
|
def initialize(@result : SuccessfulResult)
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_xml(xml : ::XML::Builder)
|
|
||||||
xml.element("testcase",
|
|
||||||
name: @result.example,
|
|
||||||
status: @result,
|
|
||||||
time: @result.elapsed.total_seconds,
|
|
||||||
classname: classname,
|
|
||||||
assertions: @result.expectations.size)
|
|
||||||
end
|
|
||||||
|
|
||||||
private def classname
|
|
||||||
"TODO"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue