![]() |
T4S4
19.1 C8540 A23673
Teamcenter Gateway for SAP S/4HANA API Reference
|
Commands to work with the Test and Teach framework (TNT). More...
Namespaces | |
Assert | |
Commands to compare expected with actual results. They must only be called from within verify procedures. Call them without any namespace identifier. | |
DefinitionLanguage | |
Commands to create and configure demo cases and groups. | |
DemoCase | |
Commands to retrieve information about the demo case currently being executed. They must only be called from within demo case namespaces. | |
DemoSuite | |
Commands to retrieve information about the demo suite currently being executed. They must only be called from within demo case namespaces. | |
Functions | |
canExecuteDemoSuite namespace ?optionsVar? | |
Test whether all preconditions defined in a demo suite are met. More... | |
executeDemoSuite namespace testResultsVar ?optionsVar? | |
Execute demo suite as a test. More... | |
executeTests args | |
Execute demo suite as a test (deprecated). More... | |
formatTestReport testResultsVar | |
Format the test results into a list of lines. More... | |
getNetResult testResultsIn | |
getNonGood testResultsIn | |
Returns the list of demo cases that did not complete with GOOD. More... | |
getStatus testResultsIn demoCase | |
htmlCloseFile channel ?optionsVar? | |
Close an HTML file opened to receive the documentation to be generated through the htmlWriteLessons command. More... | |
htmlOpenFile htmlOutputFileName ?optionsVar? | |
Open an HTML file to receive the documentation to be generated through the htmlWriteLessons command. More... | |
htmlWriteLessons outChannel namespace ?optionsVar? | |
Derive documentation from a demo suite and write it to an HTML file. More... | |
logTestReport testResultsVar ?logChannel? | |
Output test results using the tpwrite command. More... | |
putCode namespace ?optionsVar? | |
Generate code from the demo suite and output the code using the puts command. More... | |
putLessons namespace ?optionsVar? | |
Output the title, lesson and code parts of demo suite using the puts command. More... | |
putOverview namespace ?optionsVar? | |
Output the title, and code parts of demo suite using the puts command. More... | |
putTestReport testResultsVar | |
Output test results using the puts command. More... | |
setProperties fullName args | |
Assign properties to a demo case and set their values. More... | |
splitCode text width | |
succeeded testResultsIn | |
writeLessons writer namespace ?optionsVar? | |
Derive documentation from a demo suite and write it with the given writer. More... | |
Commands to work with the Test and Teach framework (TNT).
Formulate demo suites containing demo cases, similar to test suites and test cases, and feed them into the TNT using the commands in this namespace. The result will be the execution of the tests with a test report you can output or documentation in several formats.
The demo suites are specified as Tcl namespaces including subordinate namespaces for the demo cases. The demo case namespaces may include the following attributes:
precondition procedure - The code defined in this procedure is executed prior to executing the code to be tested. Like the verify procedure it may contain assertions formulated as calls to the Assert::assertEquals, Assert::assertTrue, Assert::assertFalse, etc. commands. The precondition fails if any of the assertions fails. If an assertion fails subsequent assertions will not be executed. Note that the code in a precondition procedure must not depend on any code procedure in any demo case being executed beforehand if you want to use the canExecuteDemoSuite command. See Preconditions below.
Example:
true
this demo case will not be executed unlesstrue
and the showHidden option is not set to true
the output and test result of the demo case will not be shown. This is implicitly set to true
for implicit life-cycle demo cases.true
the demo case will be executed even if there are failed dependencies. This is implicitly set to true
for TearDown life-cycle demo cases._SetUp_
or _TearDown_
resp. you need to set the type.Demo cases can have properties. A property has a name and a value. The value can be retrieved using the DemoCase::getProperty command from within a demo case and the setProperties command from outside the demo case. You can also set properties using the commands from the DefinitionLanguage namespace.
Attributes defined by writing a procedure such as code code
can call the DemoCase::getProperty command or encounter the names of the properties in their argument lists.
This can be used to parameterize demo cases.
The following example creates a demo suite with two parameterized demo cases. They only differ in the protocol HTTP or HTTPS to be used to cal a REST service:
Demo cases can be organized in groups. Groups are represented as namespaces like demo cases or demo suites. A namespace that has any of the elements that are typical for a demo case like a code proc, or a depends variable is considered a demo case. Otherwise it is considered a group. This applies to the demo suite as well.
You can create SetUp and TearDown demo cases to execute operations that create edge conditions for regular demo cases or do clean up tasks after regular demo cases have finished.
SetUp and TearDown demo cases are called life-cycle demo cases.
Life-cycle demo cases are associated with Groups. Every group, including the demo suite, has at least one SetUp and one TearDown demo case. They can be formulated as Tcl namespaces named _SetUp_
or _TearDown_
resp. or as namespaces whose type variable is set to SetUp
or TearDown
resp. If a group is lacking such namespaces implicit life-cycle demo cases will automatically be created behind the scenes. They will have the hidden attribute set to true
.
All regular demo cases of a group (DC1 and DC2 in the picture below) depend on the SetUp demo cases (SU below) of the group as shown below:
If a group (G1 below in dotted rectangle) has a parent group its SetUp demo cases depend on the SetUp demo cases of the parent group:
TearDown demo cases (TD in the picture below) depend on all demo cases (DC1 and DC2 below) of the same group:
If a group (G1 below in dotted rectangle) has a parent group its TearDown demo cases act as dependencies for the parent group:
A demo case can depend on a demo case of another group. The name given in the depends
variable is searched in the same group first then in the parent group and so on. The name can be qualified with the name of the group to address a demo case of a child or sibling group.
There is no implicit guarantee that all demo cases of one group are executed before all demo cases of another group. In order to achieve this create a dependency to the TearDown demo case of the group to be executed first from the SetUp demo case of the group to be executed afterwards:
Code example:
Groups including demo suites can have their inherits variable set. Such variables contain lists of a specific format: On odd positions there are namespace names of groups to be inherited. On even positions they have lists of glob patterns with ?
and *
as wildcards (see documentation of the string match
command). If the inherits
variable contains an odd number of element a pattern list with the *
wildcard as the only pattern is implicitly added. The pattern lists are used to select subsets of demo cases from the inherited groups.
Note that the lists don't have to be well-formed Tcl lists as produced by the list
command. This a allows for a more terse syntax than with nested list
invocations.
Demo cases inherited from groups can be overridden by demo cases in the inheriting group. They need to have the same namespace name and can redefine any attribute of the inherited demo cases.
The following examples shows how the demo suites for testing a fictional JDBC library might look like. The examples are minimized to focus on demonstrating the effects of inheritance. A real test scenario would of course contain more assertions, code and documentation.
Code example:
In the above example the ConnectToJDBCSuite
demo suite will not be executed but just used as a blue print to be inherited from. If it were executed the assertTrue [info exists connectUrl]
and assertTrue [info exists jdbcDriver]
assertions would fail. Instead the ConnectToOracleSuite
can be executed as it provides the missing pieces of code
to create the required variables.
Setting inherits to { ConnectToJDBCSuite * }
or { ConnectToJDBCSuite {*} }
is equivalent to { ConnectToJDBCSuite * }
.
Note that the type of the DisconnectDemo
demo case is explicitly set to TearDown
to ensure the connection is closed after executing the other demo cases.
Lets extend the example so that you can test SQL data definition and manipulation language statements.
Code example:
In the above example the JdbcWithOracleSuite
demo suite inherits from the ConnectToOracleSuite
so the programming code used to establish and close the data base connection does not have to be repeated.
Lets assume now you want to do the same tests with a MySql data base. You create
The tests for the SQL data definition and manipulation language statements are the same for Oracle and MySql so you will want to define them independently of the database system as shown below:
The JdbcWithOracleSuite
and JdbcWithMySqlSuite
demo suites would then become
Now you want to test your JDBCConnector product which makes use of the JDBC library and the creation of the driver class names and the connect URLs are the only pieces of code you can reuse from the demo suites so far. So write the code such that it only inherits the respective demo cases. The example assumes you want to test with the MySql database and all the tests are defined in the JDBCConnectorGroup
group.
This could be shortened to
The Specify*
pattern will be expanded to SpecifyDriverClassNameDemo
and SpecifyConnectUrlDemo
.
The demo cases and their dependencies to each other can be displayed in a graph using the Graphviz software. The TNT can create files in the dot language that can be converted to varions graphics formats or directly viewed with the zgrviewer
software.
Provide the options
array to the executeDemoSuite command and set the dot
option. See executeDemoSuite.
Test results are recorded in the testResults
array the name of which is passed to the commands as a parameter. Demo cases are assigned so called four-letter-status-words out of the following:
The precondition procedures can be used to define preconditions that must be met before the code defined in the code procedures get executed. The canExecuteDemoSuite command can then be called prior to running any test in order to check if there are unmet preconditions. This is for example useful to test if test data required to execute the demo suite is available. If not the test script may not even offer the possibility to execute the demo suite
For this to work the code in a precondition procedure must not depend on any code procedure in any demo case being executed beforehand. Only then all precondition procedures can be executed to verify if the demo suite can be executed.
Read more (including examples) under precondition proc and canExecuteDemoSuite command.
All procedures defined in a demo case such as code, precondition, verify or examples may contain placeholders of the form <%= SCRIPT%>. The SCRIPT is a piece of Tcl code that is executed when the code is retrieved from the body of the procedure. The result of the execution replaces the placeholder. This can be used for example to avoid code duplication.
If you want lines in the code procedure to not appear in the representation used for documentation purposes you can suppress them with the following markers:
The htmlWriteLessons command produces HTML output from text placed into lessons. The lessons are parsed by a simple markup processor that translates the markup into HTML elements.
The following markup elements are supported:
The value is 'true'
→ The value istrue
Click on *
File*
→ Click on File
a demo case
This is called a <<demo case>>
→ This is called
Go to File --> New ...
→ Go to File → New ...
href="#::DemoSuite::FindBomHeader">Find the header of a Bill Of Material (BOM)
See ->FindBomHeader
→ See <a
-
-! Caution !
on a single line followed by any number of dashes marks the beginning of highlighted text. The end of the highlighted text is marked with a single line consisting of at least six dashes, e.g.: is rendered as
-
-! Caution !--—
NOTE THAT ...
------------------
NOTE THAT ... |
contextType | type of stucture |
---|---|
MEProductContext | Bill of Material |
MEPlantContext | Plant |
MEProcessContext | Bill of Processes |
T4X::TNT::canExecuteDemoSuite | namespace ?optionsVar? | ||
Test whether all preconditions defined in a demo suite are met.
If you are interested in more details you can use the executeDemoSuite command with the execute option set to false
and extract the details from the result array.
namespace | the Tcl namespace representing the demo suite |
optionsVar | (optional) name of an array variable from which to read further options. Supported options are given with the executeDemoSuite command. |
true
if all preconditions are met, false
if any is not met. T4X::TNT::executeDemoSuite | namespace testResultsVar ?optionsVar? | ||
Execute demo suite as a test.
If the optionsVar
parameter is given it is interpreted as the name of an array that may contain the following entries:
true
a directed graph with the demo cases as nodes and the dependencies as edges will be written to a file. The name of the file is stored in the test result under the dotFileName
key. It can be overridden by setting the dotFileName
option. By default dot files are placed in the tmp/dot
folder in subdirectories named after the demo cases. If you also set the execute
option to false
no tests will be executed.true
also implicit demo cases will appear in the generated dot graph. See dotOption.true
also display the output and test results of hidden demo cases.true
test if all preconditions are met and write the result into the preconditionsMet
field of the result array; defaults to false
.false
no demo case will be tested. This is used in conjunction with testPrecondition
to only check the preconditions or can be used to create dot graphs without executing tests. See dotOptionvar/testdata
inside the T4x installation. The test data is used for comparisons with Assert::assertTextFilesEqual.true
the code that is being tested will be output. This is useful to verify if the angle bracket expressions are expanded in the expected way.namespace | the Tcl namespace representing the demo suite |
testResultsVar | name of an array variable into which the test result is recorded |
optionsVar | (optional) name of an array variable from which to read further options. Supported options are given above. |
T4X::TNT::executeTests | args | ||
Execute demo suite as a test (deprecated).
namespace | the Tcl namespace representing the demo suite |
executionContext | namespace inside which the tests are executed |
testResultsVar | name of an array variable into which the test result is recorded |
patterns | (optional) list of patterns to be applied to the names of demo cases (the names of the namespaces) to select which demo cases to process. The string match command is used for this and case is ignored. |
T4X::TNT::formatTestReport | testResultsVar | ||
Format the test results into a list of lines.
testResultsVar | name of an array variable containing the test results as produced by the executeDemoSuite command. |
T4X::TNT::getNetResult | testResultsIn | ||
testResultsIn | the name of the Tcl array containing the test results. |
T4X::TNT::getNonGood | testResultsIn | ||
Returns the list of demo cases that did not complete with GOOD.
T4X::TNT::getStatus | testResultsIn demoCase | ||
testResultsIn | the name of the Tcl array containing the test results. |
demoCase | the namespace name of the demo case. |
T4X::TNT::htmlCloseFile | channel ?optionsVar? | ||
Close an HTML file opened to receive the documentation to be generated through the htmlWriteLessons command.
channel | identifier representing the HTML file |
optionsVar | (optional) name of an array variable from which to read further options. |
T4X::TNT::htmlOpenFile | htmlOutputFileName ?optionsVar? | ||
Open an HTML file to receive the documentation to be generated through the htmlWriteLessons command.
htmlOutputFileName | full path of the HTML file |
optionsVar | (optional) name of an array variable from which to read further options. |
T4X::TNT::htmlWriteLessons | outChannel namespace ?optionsVar? | ||
Derive documentation from a demo suite and write it to an HTML file.
outChannel | identifier representing the HTML file |
namespace | representing the demo suite |
optionsVar | (optional) name of an array variable from which to read further options. |
T4X::TNT::logTestReport | testResultsVar ?logChannel? | ||
Output test results using the tpwrite
command.
The log lines are assigned a message type according to the status of the tests.
testResultsVar | name of an array variable containing the test results as produced by the executeDemoSuite procedure. |
logChannel | (optional) identifier of the log file to write to. |
T4X::TNT::putCode | namespace ?optionsVar? | ||
Generate code from the demo suite and output the code using the puts
command.
The generated code may be copied into real mappings but may have to be reworked afterwards.
namespace | representing the demo suite |
optionsVar | (optional) name of an array variable from which to read further options. |
T4X::TNT::putLessons | namespace ?optionsVar? | ||
T4X::TNT::putOverview | namespace ?optionsVar? | ||
T4X::TNT::putTestReport | testResultsVar | ||
Output test results using the puts
command.
testResultsVar | name of an array variable containing the test results as produced by the executeDemoSuite procedure. |
T4X::TNT::setProperties | fullName args | ||
Assign properties to a demo case and set their values.
fullName | name of the demo case |
args | list of property names and values |
T4X::TNT::splitCode | text width | ||
Simple command to split long code lines
text | code to split |
width | maximum width of the code lines. If the value is -1 the input text is returned. |
T4X::TNT::succeeded | testResultsIn | ||
testResultsIn | the name of the Tcl array containing the test results. |
true
if all demo cases succeeded or false
if at least one failed. T4X::TNT::writeLessons | writer namespace ?optionsVar? | ||
Derive documentation from a demo suite and write it with the given writer.
writer | namespace of the writer to use |
namespace | representing the demo suite |
optionsVar | (optional) name of an array variable from which to read further options. |