Typed Decision Table
npm install tdtLeveraging the power of Typescript generics, the tool ensures that the generated test cases are typed according to your specifications. This feature facilitates the accurate handling of keys and values in any test code you write.
Furthermore, not just the outputs but also some of the inputs are typed using generics, streamlining the process of preparing the necessary inputs.
Additional features of this tool include:
- File output in JSON or Markdown format.
- Support for the strength of the Covering Array.
npm install tdt###### Example:
``
const tests = generateTests({
domain,
defaults,
exclusions,
perspectives,
});
console.log(tests)
/*
[
{
'Condition.User.IsRegistered': 'True',
'Condition.User.IsAdmin': 'True',
'Condition.Device': 'Mobile',
ExpectedResult: 'Failure',
Perspective: 'Only registered users accessed from PC can access.',
ID: '1'
},
{
'Condition.User.IsRegistered': 'True',
'Condition.User.IsAdmin': 'True',
'Condition.Device': 'PC',
ExpectedResult: 'Success',
Perspective: 'Only registered users accessed from PC can access.',
ID: '2'
},
{
'Condition.User.IsRegistered': 'True',
'Condition.User.IsAdmin': 'False',
'Condition.Device': 'Mobile',
ExpectedResult: 'Failure',
Perspective: 'Only registered users accessed from PC can access.',
ID: '3'
},
{
'Condition.User.IsRegistered': 'True',
'Condition.User.IsAdmin': 'False',
'Condition.Device': 'PC',
ExpectedResult: 'Success',
Perspective: 'Only registered users accessed from PC can access.',
ID: '4'
},
{
'Condition.User.IsRegistered': 'False',
'Condition.User.IsAdmin': 'False',
'Condition.Device': 'Mobile',
ExpectedResult: 'Failure',
Perspective: 'Only registered users accessed from PC can access.',
ID: '5'
},
{
'Condition.User.IsRegistered': 'False',
'Condition.User.IsAdmin': 'False',
'Condition.Device': 'PC',
ExpectedResult: 'Failure',
Perspective: 'Only registered users accessed from PC can access.',
ID: '6'
}
]
*/
`
1. Prepare arguments of generateTests function.generateTests
1-1. Parameter domains (all potential values for the parameters).
1-2. Default values for the parameters.
1-3. Combinations of values to exclude.
1-4. Testing perspectives.
2. Call function.
###### Example:
``
const domain = {
"Condition":{
"User":{
"IsRegistered":[
"True",
"False"
],
"IsAdmin":[
"True",
"False"
]
},
"Device":[
"Mobile",
"PC"
]
},
"ExpectedResult":[
"Success",
"Failure",
"Any"
]
} as const;
type ExampleDomain = typeof domain;2.
Unlike other inputs, this one isn't typed as a generic type. You have the flexibility to define its structure, provided it meets the necessary criteria. Based on this structure, the subsequent inputs (items , 3., and 4.) will be automatically typed.
#### 1-2. Default Values for the Parameters
Specify the default values for the parameters outlined in section 1.. For each parameter, select a value from the list of potential values. These defaults are used when a parameter value isn't explicitly set in a test case.`
###### Example:`
const defaults : Defaults
"Condition":{
"User":{
"IsRegistered" : "True",
"IsAdmin" : "False"
},
"Device":"Mobile"
},
"ExpectedResult":"Any"
} as const;
#### 1-3. Combinations of Values to Exclude
Use this to omit combinations of parameter values that are either impossible or lack significance. Multiple combinations can be excluded.
###### Example:
``
const exclusions:Exclusions
{
"Condition.User.IsRegistered" : "False",
"Condition.User.IsAdmin" : "True"
}
] as const;
#### 1-4. Testing Perspectives
This determines the approach for generating test cases. Typically, test cases should be formulated based on a specific perspective or focus. Hence, this tool generates all test cases in alignment with the provided perspectives.
###### Example:
``
const perspectives:Perspectives
{
"title": "Only registered users accessed from PC can access.",
"constants": {},
"variables": [
"Condition.User.IsRegistered",
"Condition.User.IsAdmin",
"Condition.Device",
],
"expect": (test:Test
if(
test["Condition.User.IsRegistered"] === "True" &&
test["Condition.Device"] === "PC"
){
test["ExpectedResult"] = "Success";
}else{
test["ExpectedResult"] = "Failure";
}
return test
},
}
] as const;`$3
`
const tests = generateTests({
domain,
defaults,
exclusions,
perspectives,
});
console.log(tests)
arguments, you can export the test cases to files.###### Example of setting an option:
`:diff
const tests = generateTests({
domain,
defaults,
exclusions,
perspectives,
+ export_option: {
+ json:{
+ file_path: '01.json',
+ },
+ markdown:{
+ file_path: '01.md',
+ true_symbol: 'X',
+ false_symbol: '-'
+ }
+ }
});
`
###### Example of a JSON file:
`
[
{
"Condition.User.IsRegistered": "True",
"Condition.User.IsAdmin": "True",
"Condition.Device": "Mobile",
"ExpectedResult": "Failure",
"Perspective": "Only registered users accessed from PC can access.",
"ID": "1"
},
{
"Condition.User.IsRegistered": "True",
"Condition.User.IsAdmin": "True",
"Condition.Device": "PC",
"ExpectedResult": "Success",
"Perspective": "Only registered users accessed from PC can access.",
"ID": "2"
},
{
"Condition.User.IsRegistered": "True",
"Condition.User.IsAdmin": "False",
"Condition.Device": "Mobile",
"ExpectedResult": "Failure",
"Perspective": "Only registered users accessed from PC can access.",
"ID": "3"
},
{
"Condition.User.IsRegistered": "True",
"Condition.User.IsAdmin": "False",
"Condition.Device": "PC",
"ExpectedResult": "Success",
"Perspective": "Only registered users accessed from PC can access.",
"ID": "4"
},
{
"Condition.User.IsRegistered": "False",
"Condition.User.IsAdmin": "False",
"Condition.Device": "Mobile",
"ExpectedResult": "Failure",
"Perspective": "Only registered users accessed from PC can access.",
"ID": "5"
},
{
"Condition.User.IsRegistered": "False",
"Condition.User.IsAdmin": "False",
"Condition.Device": "PC",
"ExpectedResult": "Failure",
"Perspective": "Only registered users accessed from PC can access.",
"ID": "6"
}
]
`
###### Example of a Markdown file:
|||#1|#2|#3|#4|#5|#6|
|--|--|--|--|--|--|--|--|
|Condition.User.IsRegistered|True|X|X|X|X|-|-|
||False|-|-|-|-|X|X|
|Condition.User.IsAdmin|True|X|X|-|-|-|-|
||False|-|-|X|X|X|X|
|Condition.Device|Mobile|X|-|X|-|X|-|
||PC|-|X|-|X|-|X|
|ExpectedResult|Success|-|X|-|X|-|-|
||Failure|X|-|X|-|X|X|
||Any|-|-|-|-|-|-|
$3
By default, this tool generates all possible combinations of the variables defined in the perspectives. However, this can result in a significantly large number of test cases.To mitigate this, you can set the
strength for each perspective. By adjusting the strength, less relevant test cases will be filtered out. The strength value can range from 2 up to the total number of variables in the perspective. A lower strength value will yield fewer test cases.For instance, if the
perspective is structured as below, and there are 3 variables, the strength can be set anywhere between 2 and 3.###### Example of setting the
strength:
`:diff
{
"title": "Only registered users accessed from PC can access.",
"constants": {},
"variables": [
"Condition.User.IsRegistered",
"Condition.User.IsAdmin",
"Condition.Device",
],
"expect": (test:Test)=>{
if(
test["Condition.User.IsRegistered"] === "True" &&
test["Condition.Device"] === "PC"
){
test["ExpectedResult"] = "Success";
}else{
test["ExpectedResult"] = "Failure";
}
return test
},
+ "strength" : 2,
}
``