RTestCase: Constructor for RTestCase

Description Usage Arguments Value Author(s) Examples

View source: R/RTestCase.R

Description

Constructor for RTestCase

Usage

1
2
3
RTestCase(ID = NULL, tc.type = NULL, synopsis = NULL,
  xml.fPath = NULL, xml.root = NULL, input.data = NULL,
  tests = NULL, test.for = NULL, test.result = NULL)

Arguments

ID

(character) ID of the TC.

tc.type

(character) Type of the TC (i.e. the class name).

synopsis

(list) Synopsis information of the TC (as defined in the XSD ComplexType 'RTestSynopis').

xml.fPath

(character) Path to XML definition file of the TC.

xml.root

(XMLNode) The imported TC definition as XMLNode-class object.

input.data

(list) The input data of the test case, which will be filled using the method readXMLInputData.

tests

(list) A list with the test results or NULL, if the test case has not been executed (see 'Details').

test.for

(character) Names of the packages, which were tested in the last execution of the test case. NULL, if the test case has not been executed.

test.result

(character) Result of the last test case execution ('SUCCESS' or 'FAILURE'). NULL, if the test case has not been executed.

Value

(.Object) RTestCase-class Object

Author(s)

Matthias Pfeifer matthias.pfeifer@roche.com

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
library(RTest)

xml.root <- XML::newXMLNode("func01")
RTest::xmlFromList(xml.root,
    list(
        params=list(mult=list(attributes=c(value="1",type="numeric"))),
        testspec=list(
execution=list(attributes=c("execution-type"="silent")),
"return-value"=list(attributes=c(
"compare-type"="equal",
"diff-type"="absolute",
"tolerance"=0.001
))
        )
    )
)
# Add the reference result to the params and testspec and read it in again
xml.root <- XML::xmlRoot(XML::xmlTreeParse(
        paste0("<root>",
            capture_output(print(xml.root[[1]])),
            capture_output(print(xml.root[[2]])),
            paste(xmlWriteData_data.frame(
                    "reference",
                    data=data.frame(x=c(1,1),y=c(2,2),sum=c(3,3)),
                    printXML=FALSE)
                ,collapse="\n"),"</root>")
    ))

# Define what to test in the first test
# Please check the function test.RTest.funct_01 to see
# how it tests the code of the function ("test_fun")
tests <- new.env()
testEntry <- list(
    "pkg"            = "RTest",                  # test description
    "pgk-iter"       = "1",
    "func"           = "funct_01",
    "func-iter"      = "1",
    "test-code"      = "RTest::test_fun",
    "test-adapter"   = "RTestCase",
    "test-func"      = "test.RTest.funct_01",
    "pkg-desc"       = "no package desc",
    "func-desc"      = "Simple add func",
    "xpath"          = "/root",
    "reporter"       = NA,   # field for testthat reporter
    "result"         = NA,   # field for test result (failed/success)
    "cache"          = NA,   # field for caching test results
    "execresid"      = NA,   # field for test execution result id
    "specid"         = "0",   # field for test function id
    "riskid"         = "0"   # field for test function risk id
)

# Assign test entry to test environment
#      pkg-name  pkg-iter    func-name  func-iter
tests[["RTest"]][["1"]][["funct_01"]][["1"]] <- testEntry

# Create a TestCase Object
object <- RTestCase(
    ID="1",
    tc.type="RTestCase",
    synopsis= list(version="v1",author="Sebastian Wolf"),
    xml.fPath="",
    xml.root=xml.root,
    input.data=list("one"=
            data.frame(x=c(1,1),y=c(2,2))
    ),
    tests=tests,
    test.for="RTest",
    test.result=NA
)

# Run the test
object <- test(object,test.for="RTest")
stopifnot(object@test.result=="success")

# Run a failing test

object@input.data <- list("one"=
        data.frame(x=c(1,2),y=c(2,1))
)
object <- test(object,test.for="RTest")
stopifnot(object@test.result=="failed")

RTest documentation built on Dec. 4, 2019, 5:07 p.m.