forked from finos/morphir
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added docs for generating test cases in scala
- Loading branch information
1 parent
4d95595
commit 94370b3
Showing
3 changed files
with
148 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
# Generating Scala Test Cases | ||
|
||
Morphir offers a way to generate scala test cases from test cases created using the morphir develop UI. | ||
|
||
Test cases can be generated by adding additional flags to the gen command, i.e `morphir scala-gen [test-gen-flag]`. | ||
The gen flags for tests can be mixed together to generate different kinds of test. | ||
Generating tests creates a sub-package called `_morphirtests`, at the package root of the generated scala, containing scala files | ||
matching the selected kind of test(s). | ||
|
||
Here's what the packages look like if your Morphir project is named `**foo**` | ||
```js | ||
- foo/ /* package root */ | ||
- (...) /* other sub packages and files */ | ||
- _morphirtests/ | ||
- [TestKind].scala /* eg: GenericTest.Scala */ | ||
``` | ||
|
||
## Flags for Tests Generation | ||
|
||
This tooling also provides some flags to generate a runnable test suite using scala test | ||
or just generate generic test cases. | ||
|
||
### Using `--generate-test-generic` | ||
|
||
```shell | ||
Usage: | ||
morphir scala-gen --generate-test-generic | ||
``` | ||
|
||
This generates a scala value with a `TestCase` case class. | ||
Example: | ||
|
||
```scala | ||
/* | ||
testInput = | ||
{ | ||
input = "Foo", | ||
expectedOutput = "Foo", | ||
description = "foo description" | ||
} | ||
*/ | ||
|
||
object MorphirTests { | ||
case class TestCase(input: Any, expectedOutput: Any, description: String) | ||
|
||
val testCases : List[TestCase] = List( | ||
TestCase( | ||
input = "Foo", | ||
expectedOutput = "Foo", | ||
description = "testInput test1 - foo description" | ||
) | ||
) | ||
} | ||
|
||
``` | ||
|
||
#### Using the generated test cases | ||
|
||
You will need to manually write out the tests in scala and import the generated testcases | ||
|
||
**_example:_** | ||
|
||
```scala | ||
test("morphir tests should not fail") { | ||
val suite = MorphirTests.testCases | ||
|
||
suite.foreach((testcase) => { | ||
assertResult(testcase.expectedOutput)(testcase.input) | ||
}) | ||
} | ||
``` | ||
|
||
### Using `--generate-test-scalatest` | ||
|
||
```shell | ||
Usage: | ||
morphir scala-gen --generate-test --test-strategy=ScalaTest | ||
``` | ||
|
||
This generates a complete runnable test suite that just can be run. | ||
To create a test description, it uses | ||
|
||
- the fully qualified function name | ||
- a sequential integer | ||
- and the original description provided. | ||
|
||
**_example:_** | ||
|
||
```scala | ||
/* | ||
testInput = | ||
{ | ||
input = "Foo", | ||
expectedOutput = "Foo", | ||
description = "foo description" | ||
} | ||
*/ | ||
|
||
class MorphirTests extends AnyFunSuite { | ||
test("testInput test1 - foo description") { | ||
assertResult("Foo")("Foo") | ||
} | ||
} | ||
``` |