Generator

.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.

OpenAPI Spec

Select a File to Load:
openapi: 3.0.1 info: title: Example Store description: Example Store Application for Tutorial. version: '1.0' servers: - url: http://cots-service.com/example/store tags: - name: user description: Endpoints related to users. paths: /health: get: tags: - status operationId: getHealth summary: Retrieves system health information responses: '200': description: Successful response content: application/json: schema: $ref: '#/components/schemas/Health' /user: post: tags: - user operationId: addUser summary: Adds a user description: Records the details of a new user. requestBody: content: multipart/form-data: schema: type: object properties: username: type: string example: George required: true responses: 201: description: The user was sucessfully added. content: application/json: schema: $ref: '#/components/schemas/User' 400: description: Bad request. content: application/json: schema: $ref: '#/components/schemas/RestError' 500: description: Server error. content: application/json: schema: $ref: '#/components/schemas/RestError' get: tags: - user operationId: listUsers summary: Lists users description: Returns an array of users. responses: 200: description: Owner details found and returned. headers: ETag: description: An ID for this version of the response. schema: type: string content: application/json: schema: type: array items: $ref: '#/components/schemas/User' 304: description: Not modified. headers: ETag: description: An ID for this version of the response. schema: type: string 500: description: Server error. content: application/json: schema: $ref: '#/components/schemas/RestError' /user/{id}: get: tags: - user operationId: getUserById summary: Retrieve user by id description: Returns an array of users matching with the specified id. parameters: - in: path name: id required: true schema: type: integer responses: 200: description: User details found and returned. headers: ETag: description: An ID for this version of the response. schema: type: string content: application/json: schema: type: array items: $ref: '#/components/schemas/User' /user/{id}/collection: post: tags: - collection operationId: createCollection summary: Create a collection description: Returns a collection assigned to a particular user parameters: - in: path name: id required: true schema: type: integer requestBody: content: multipart/form-data: schema: type: object properties: name: type: string example: collection1 responses: '200': description: Successful response content: application/json: schema: $ref: '#/components/schemas/Collection' get: tags: - collection operationId: getCollection summary: Retrieve a collection description: Returns a collection via its id parameters: - in: path name: id required: true schema: type: integer responses: '200': description: Successful response content: application/json: schema: type: array items: $ref: '#/components/schemas/Collection' components: schemas: RestError: title: REST Error description: The schema for all error responses. type: object properties: status: title: Status description: The HTTP status code. type: integer format: int32 example: 400 readOnly: true error: title: Error description: The short error message. type: string example: Bad Request readOnly: true path: title: Path description: The path of the URL for this request. type: string format: uri example: '/api/owners' readOnly: true timestamp: title: Timestamp description: The time the error occured. type: string format: date-time example: '2019-08-21T21:41:46.158+0000' readOnly: true message: title: Message description: The long error message. type: string example: 'Request failed schema validation' readOnly: true schemaValidationErrors: title: Schema validation errors description: Validation errors against the OpenAPI schema. type: array items: $ref: '#/components/schemas/ValidationMessage' trace: title: Trace description: The stacktrace for this error. type: string example: 'com.atlassian.oai.validator.springmvc.InvalidRequestException: ...' readOnly: true required: - status - error - path - timestamp - message - schemaValidationErrors ValidationMessage: title: Validation message description: Messages describing a validation error. type: object properties: message: title: Message description: The valiation message. type: string example: "[Path '/lastName'] Instance type (null) does not match any allowed primitive type (allowed: [\"string\"])" readOnly: true required: - message additionalProperties: true Health: title: Health description: System health information type: object properties: health: title: Health description: The health information. type: string minLength: 1 maxLength: 30 pattern: '^[a-zA-Z]*$' example: OK required: - health UserFields: title: User fields description: Editable fields of a user. type: object properties: username: title: Username description: The username of the user. type: string minLength: 1 maxLength: 30 pattern: '^[a-zA-Z]*$' example: George User: title: User description: A user. allOf: - type: object properties: id: title: ID description: The ID of the user. type: integer format: int32 minimum: 0 example: 1 readOnly: true username: title: Username description: The username of the user. type: string minLength: 1 maxLength: 30 pattern: '^[a-zA-Z]*$' example: George Collection: title: Collection description: A collection allOf: - type: object properties: assignedto: title: assignedto description: The id of the user the collection belongs to. type: integer format: int32 minimum: 0 example: 1 collectionname: title: collectionname description: The name of the collection. type: string minLength: 1 maxLength: 30 pattern: '^[a-zA-Z]*$' example: Chris' collection id: title: id description: The id of the collection. type: integer format: int32 minimum: 0 example: 1
Getting Started
Generating Test Drivers
Running Test Drivers
Analysing Test Results