factor10 / intent

Test framework for Dotty
https://factor10.github.io/intent/
Apache License 2.0
13 stars 4 forks source link

Better DSL #51

Open sirinath opened 3 years ago

sirinath commented 3 years ago

I believe the current DSL can be improved. E.g.:

class StatefulTest extends TestSuite with State:
  setup:
  - "an empty cart" Cart() as "myCart":
  - "another empty cart" Cart() as "anotherCart":
  where:
    - tabular:
      +
      * | "beachChair" | "sunScreen" | "total":
      -
      "quantity" |  2  |  3  |  5 :
      "price" |  2  |  3  |  5 :
  then:
  - sequentially:
    - "add two items" using "myCart" '{_.add(CartItem("Beach chair", data["beachChair"]["quantity"]))}:
    - parallelly:
       - ....
       - ....
       - sequentially:
         - ....
         - ....
    - "add another three items" '{state["myCart"].add(CartItem("Sunscreen", data["sunScreen"]["quantity"]))}:
  expect:
  - "contains 5 items" '{state["myCart"].totalQuantity == data["total"]["quantity"]} and:
  - "costing" using "myCart" '{_.totalPrice == data["total"]["price"]}:
  lastly:
  - "do some cleanup" using (_.close())

For table tests can they be specified like:

class MaxTest extends TestSuite with Stateless:
  expect:
    - "Max of a and b" '{ Math.max(data["a"], data["b"]) == data["c"] }

  where:
    - tabular:
      +
      | "a" | "b" | "c":
      -
      |  1  |  3  |  3 :
      |  7  |  4  |  7 :
      |  0  |  0  |  0 :