.st file
S_store=rec X.(+{!UserApi.addUser(username: String(const "Chris")).?C201(user: User)< util.setUserId(user)>.
!UserApi.listUsers().?C200(users: "Seq[String]").
!CollectionApi.createCollection(id: Int(getUserId), name: String(const "Chris' collection")).?C201(collection: Collection)< util.checkCollection(collection)>.
!CollectionApi.getCollection(id).?C200(collections: "Seq[Collection]")< util.checkCollections(collections)>,
!CollectionApi.getCollection(id: Int(getRandomId)).?C404(),
!StatusApi.getHealth().?C200(health: Health).X
})
Util file
package store
import store.model._
import scala.util.Random
object util {
//write generator functions and assertions here
def genInt(rand: Random): Int = {
rand.nextInt()
}
def const(string: String, rand: Random): Option[String] = {
Some(string)
}
def assertEmpty(name: String): Boolean = {
name.isEmpty()
}
def getUserFields(rand: Random): UserFields = {
UserFields.apply(Some("test"))
}
var user: User = null
def setUserId(user: User): Boolean = {
this.user = user
true
}
def getUserId(rand: Random): Int = {
user.id.get
}
def checkCollection(collection: Collection): Boolean = {
collection.assignedto.get == user.id.get
}
def checkCollections(collections: Seq[Collection]): Boolean = {
for (collection <- collections){
return collection.assignedto.get == user.id.get
}
true
}
def getRandomId(rand: Random): Int = {
-1
}
}
Follow these steps to generate and package a test driver:
1. Import the schema file in .yaml
format (in the editor on the right).
2. Write the specification in the .st
editor by:
a. Finding the respective operationId
of the operation from the OpenAPI spec.
b. Writing the operationId
prefixed with the respective tag
in the .st
editor.
c. Writing any functions required (such as generators or assertions) in the Util
file.
3. Once the specification is ready, in the text box next to "Package Name" write the respective package name (store
in the case of the example) and click on "Generate Driver".
4. In the downloaded file, open a terminal and run "sbt assembly" which will package the driver files, avoiding compilation every time we want to execute the driver.
5. To run the driver itself, execute: java -cp target/scala-2.13/$(package)-assembly-0.0.3.jar $(package).Wrapper $(iterations)
Replace $(package)
with the respective package name and $(iterations)
with the number of tests to be executed.
6. The test driver should execute automatically on the SUT.