Skip to content

Getting Started

authorjapps edited this page Oct 14, 2019 · 7 revisions

Table of contents

Steps

Add this maven dependencies in test scope which transitively brings in JUnit lib.

<dependency>
    <groupId>org.jsmart</groupId>
    <artifactId>zerocode-tdd</artifactId>
    <version>1.3.x</version> <!-- Pick the latest release -->
    <scope>test</scope>
</dependency>

Latest release: 1.3.x - Click me 🏹

Then annotate your JUnit test method pointing to the JSON/YAML scenario-file as below via @Scenario and run as a JUnit test. That's it really!

@TargetEnv("github_host.properties")
@RunWith(ZeroCodeUnitRunner.class)
public class JustHelloWorldTest {

    @Test
    @Scenario("helloworld/hello_world_scenario_happy_path.json")
    public void testGet() throws Exception {

    }
}

Where, the hello_world_scenario_happy_path.json looks like below.

                          hello_world_scenario_happy_path.json
                          ------------------------------------
{
    "scenarioName": "Validate the GET api @@Richard",
    "steps": [
        {
            "name": "get_user_details",
            "url": "/users/octocat",
            "method": "GET",
            "request": {
                "headers" : { 
                   "Content-Type" : "application/json"
                }
            },
            "verify": {
                "status": 200,
                "headers" : { 
                   "Content-Type" : [ "application/json; charset=utf-8" ]
                },
                "body": {
                    "login" : "octocat"
                }
            }
        }
    ]
}

the github_host.properties looks as below:

                       github_host.properties
                       ----------------------
web.application.endpoint.host=https://api.github.com
web.application.endpoint.port=443
web.application.endpoint.context=

Or using YAML:

                       hello_world_scenario_happy_path.yaml
                       ------------------------------------

---
scenarioName: Validate the GET api @@Richard
steps:
- name: get_user_details
  url: "/users/octocat"
  method: GET
  request:
    headers:
      Content-Type: application/json
  verify:
    status: 200
    headers:
      Content-Type:
      - application/json; charset=utf-8
    body:
      login: octocat

Runner:

@TargetEnv("github_host.properties")
@RunWith(ZeroCodeUnitRunner.class)
public class JustHelloWorldTest {

    @Test
    @Scenario("helloworld/hello_world_scenario_happy_path.yaml")
    public void testGet() throws Exception {

    }
}

An User-Journey Test Scenario Example

Visit this User-Journey CRUD testing automation

Try-at-home examples

Clone or Download the HelloWord project, and follow the Steps to Run Hello World

Blogs

Clone this wiki locally
You can’t perform that action at this time.