Skip to content

Commit

Permalink
doc: improve the example in the first tutorial (#916)
Browse files Browse the repository at this point in the history
  • Loading branch information
monperrus authored and danglotb committed Nov 4, 2019
1 parent 0c8f83c commit 4ade619
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,38 @@ After having downloaded DSpot (see the previous section), you can run the provid
java -jar target/dspot-LATEST-jar-with-dependencies.jar --example
```

replacing `LATEST` by the latest version of DSpot, _e.g._ `2.2.1` would give :
`dspot-2.2.1-jar-with-dependencies.jar`
replacing `LATEST` by the latest version of DSpot, _e.g._ `2.2.1` would give `dspot-2.2.1-jar-with-dependencies.jar`

Given a test case as input, with `--amplifiers=None`, DSpot only adds assertions in the test, for example:

```diff
@Test
void test() {
Tacos tacos = new Tacos();
Benjamin benjamin = new Benjamin();
benjamin.eat(tacos);
assertFalse(benjamin.isHungry());
+ assertTrue(benjamin.isHappy()); // new assertion
}
```

With some amplifiers, eg `--amplifiers=AllAmplifiers`, DSpot modifies the setup of the input test and adds assertions in your code, for example:

This example is an implementation of the function `chartAt(s, i)` (in `src/test/resources/test-projects/`), which
returns the char at the index _i_ in the String _s_.

In this example, DSpot amplifies the tests of `chartAt(s, i)` with the `FastLiteralAmplifier,`, which modifies literals inside the test and the generation of assertions.
```diff
@Test
void test() {
Tacos tacos = new Tacos();
Benjamin benjamin = new Benjamin();
- benjamin.eat(tacos); // removed method call
- assertFalse(benjamin.isHungry());
+ assertTrue(benjamin.isHungry());
+ assertFalse(benjamin.isHappy()); // new assertion
}
```

When an amplification is successful, DSpot outputs the improvement on the console and the result of the amplification (the new tests) are written to the output folder specified by configuration property `outputDirectory` (default to `./target/dspot/output/`).

The result of the amplification of charAt consists of 6 new tests, as shown in the output below. These new tests are
written to the output folder specified by configuration property `outputDirectory` (`./target/dspot/output/`).

```
Initial instruction coverage: 30 / 34
Expand Down

0 comments on commit 4ade619

Please sign in to comment.