Skip to content

Commit

Permalink
Updated instructions on how to run a subset of tests from the command…
Browse files Browse the repository at this point in the history
… line
  • Loading branch information
Sdaas committed Oct 16, 2020
1 parent 4210ba7 commit 8f449f5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
20 changes: 16 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,31 @@ $ mvn test
Note that the `maven surefire plugin` is configured to treat all `.java` files in `com.daasworld` as Test classes
and to ignore all tests in the `karate` folder.


#### Running the Karate Tests
##### From Command Line

Karate does NOT start up the system under test. So first start up the application by running
```
$ mvn spring-boot:run
```

From the command-line, run

To run all the tests ( they are all under `karate`), run
```
$ mvn test -Dtest=KarateTests
```
To run only the tests under the `karate/hello`, run
```
$ mvn test -Dtest=HelloRunner
```
To run only a single feature, specify it in the `karate.options` as shown below
```
$ mvn test "-Dkarate.options=classpath:karate/hello/hello1.feature" -Dtest=HelloRunner
```
To run only a single scenario, specify its line number as shown below
```
$ mvn test "-Dkarate.options=classpath:karate/hello/hello1.feature:13" -Dtest=HelloRunner
```

##### From IntelliJ

The Karate tests can also be invoked from within IntelliJ in multiple ways

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
package com.daasworld.hellokarate.controllers;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class GreetingController {

private Logger logger = LoggerFactory.getLogger(this.getClass().getName());

// $ curl localhost:8080/api/hello
@GetMapping(value = "/api/hello", produces = "application/txt")
public String greet(@RequestParam(required=false, defaultValue = "world") String name) {
logger.info("greet() called");
return String.format("Hello %s!", name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public PersonController(PersonService personService) {
// $ curl localhost:8080/api/person/1
@GetMapping(value = "/api/person/{id}", produces = "application/json")
public ResponseEntity<Person> getById(@PathVariable int id){
logger.info("getById() called");
Person p = personService.getById(id);
if(p == null ) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
Expand All @@ -35,6 +36,7 @@ public ResponseEntity<Person> getById(@PathVariable int id){
// $ curl -X POST localhost:8080/api/person -H 'Content-type:application/json' -d '{"firstName": "John", "lastName" : "Doe", "age" : 30}'
@PostMapping(value = "/api/person", consumes = "application/json", produces = "application/json")
public ResponseEntity<Integer> createPerson(@RequestBody Person p) {
logger.info("createPerson() called");
int id = personService.add(p);
return new ResponseEntity<>(id, HttpStatus.OK);
}
Expand Down

0 comments on commit 8f449f5

Please sign in to comment.