Skip to content

Commit a2ca6f5

Browse files
committed
copyedit gui->testing
1 parent 3d91c80 commit a2ca6f5

File tree

4 files changed

+274
-168
lines changed

4 files changed

+274
-168
lines changed

doc/client/testing/Adding-Unit-Tests.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Adding tests
22

3-
For more detailed information see [an_introduction_to_unit_testing.rst](An-Introduction-to-Unit-Testing).
3+
:::{seealso}
4+
- [Introduction to unit testing](An-Introduction-to-Unit-Testing)
5+
:::
46

57
It is relatively simple to add unit tests for a plug-in in such a way that maven can run them as part of the build.
68

@@ -9,7 +11,8 @@ Here are the steps required in Eclipse:
911
* Create a new Fragment Project
1012
* File > New > Project... > Plug-in Development > Fragment Project
1113
* Set the project name to `\<the full name of the plug-in to test\>.tests`
12-
* Change the location to the repository rather than the workspace: `xxx\ibex_gui\base\\\<project_name>` (don't forget the project name!!)
14+
* Change the location to the repository rather than the workspace: `xxx\ibex_gui\base\\\<project_name>` (don't
15+
forget the project name!!)
1316
* Click "Next"
1417
* Make sure the Execution Environment points at the correct version of Java (currently JavaSE-11)
1518
* Click the "Browse" button next to "Plug-in ID"
@@ -27,7 +30,8 @@ Here are the steps required in Eclipse:
2730
* The class name **must** end in Test to be picked up by the automated build
2831

2932
* Add tests to the class
30-
* Add `org.junit` and `org.mockito` (if required) to the 'Required Plug-ins', under the Dependencies tab for the manifest
33+
* Add `org.junit` and `org.mockito` (if required) to the 'Required Plug-ins', under the Dependencies tab for the
34+
manifest
3135

3236
* Add the test plug-in to the Maven build by [following these steps](../coding/Adding-a-Plugin-or-Feature-to-Maven-Build)
3337

doc/client/testing/System-Testing-with-Squish-BDD.md

Lines changed: 67 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,37 @@
22

33
## BDD and Gherkin Overview
44

5-
Behaviour-Driven Development (BDD) is a software development process that builds on the lessons learnt from Test-Driven Development (TDD). BDD focuses on developing a common understanding of the behaviour of an application. More details can be found at https://cucumber.io/docs/bdd/ and https://www.agilealliance.org/glossary/bdd/.
5+
Behaviour-Driven Development (BDD) is a software development process that builds on the lessons learnt from Test-Driven
6+
Development (TDD). BDD focuses on developing a common understanding of the behaviour of an application. More details can
7+
be found at https://cucumber.io/docs/bdd/ and https://www.agilealliance.org/glossary/bdd/.
68

7-
BDD works by describing the behaviours of an application in a language that can be understood by developers and users, the Gherkin language https://cucumber.io/docs/gherkin/reference/, enabling a conversation on detailed application behaviour. This language helps to accurately describe behaviour and provides a way to carefully consider what to build. Gherkin is most effective for designing software when combined with other techniques such as low-fidelity prototypes.
9+
BDD works by describing the behaviours of an application in a language that can be understood by developers and users,
10+
the Gherkin language https://cucumber.io/docs/gherkin/reference/, enabling a conversation on detailed application
11+
behaviour. This language helps to accurately describe behaviour and provides a way to carefully consider what to build.
12+
Gherkin is most effective for designing software when combined with other techniques such as low-fidelity prototypes.
813

9-
Gherkin also helps to automate testing. The steps in a `.feature` (gherkin) file can be linked to the code that runs the test step on the application. Squish supports this with its BDD tools https://www.froglogic.com/squish/features/bdd-behavior-driven-development-testing/. We have made use of this in the script generator for all its Squish testing. These tests can now act as documentation of the behaviour of the application and can be used to discuss the intricacies of the behaviour with scientists.
14+
Gherkin also helps to automate testing. The steps in a `.feature` (gherkin) file can be linked to the code that runs the
15+
test step on the application. Squish supports this with its BDD tools
16+
https://www.froglogic.com/squish/features/bdd-behavior-driven-development-testing/. We have made use of this in the
17+
script generator for all its Squish testing. These tests can now act as documentation of the behaviour of the
18+
application and can be used to discuss the intricacies of the behaviour with scientists.
1019

1120
## Structure of our tests
1221

13-
Squish is split up into test suites, the script generator tests are all in the `suite_script_gen_tests`. The test cases in this suite are the `.feature` files that describe the behaviour in Gherkin. In general, we define one or more features in each file with the `Feature:` tag and each feature has a collection of scenarios denoted by the `Scenario:` tag. The feature will have a title and a description and a scenario will have a title that acts as its description.
22+
Squish is split up into test suites, the script generator tests are all in the `suite_script_gen_tests`. The test cases
23+
in this suite are the `.feature` files that describe the behaviour in Gherkin. In general, we define one or more
24+
features in each file with the `Feature:` tag and each feature has a collection of scenarios denoted by the
25+
`Scenario:` tag. The feature will have a title and a description and a scenario will have a title that acts as its
26+
description.
1427

15-
Each scenario is made up of a set of `Given`, `When`, `Then` steps. These steps can take parameters including whole tables and can be ordered in lots of different ways. `Given` generally describes the state the application should be in before a user action, `When` describes a user action and `Then` describes verification of the state of the application after a user action. More details can be found at https://cucumber.io/docs/gherkin/ and in the Squish tutorials on https://www.froglogic.com/squish/features/bdd-behavior-driven-development-testing/.
28+
Each scenario is made up of a set of `Given`, `When`, `Then` steps. These steps can take parameters including whole
29+
tables and can be ordered in lots of different ways. `Given` generally describes the state the application should be in
30+
before a user action, `When` describes a user action and `Then` describes verification of the state of the application
31+
after a user action. More details can be found at https://cucumber.io/docs/gherkin/ and in the Squish tutorials on
32+
https://www.froglogic.com/squish/features/bdd-behavior-driven-development-testing/.
1633

17-
The `Given`, `When` and `Then` steps are linked to code which is stored in the test suite resources steps area. For example, the `then_tooltip.py` file contains `Then` steps related to tooltip behaviour. Steps are defined like this:
34+
The `Given`, `When` and `Then` steps are linked to code which is stored in the test suite resources steps area. For
35+
example, the `then_tooltip.py` file contains `Then` steps related to tooltip behaviour. Steps are defined like this:
1836

1937
```python
2038
@Then("the following actions have a tooltip |word|")
@@ -23,34 +41,63 @@ def step(context, status):
2341
do_test_code()
2442
```
2543

26-
This step takes a table as a parameter (accessed through `context.table`) and a word parameter (described by the decorator with `|word|` and passed to the step function as `status`). A step can have multiple decorators of `@Given`, `@When` and `@Then`. There are also more abilities such as using `From` sections and passing data between tests through the context variable - details at https://doc.froglogic.com/squish/latest/api.bdt.functions.html.
44+
This step takes a table as a parameter (accessed through `context.table`) and a word parameter (described by the
45+
decorator with `|word|` and passed to the step function as `status`). A step can have multiple decorators of
46+
`@Given`, `@When` and `@Then`. There are also more abilities such as using `From` sections and passing data between
47+
tests through the context variable - details at https://doc.froglogic.com/squish/latest/api.bdt.functions.html.
2748

28-
We do not generally edit the test.py file in the test case resources scripts. This script is created by squish and handles starting up tests and setting up the hooks. This could be used to start up the client instead of using `@OnFeatureStart` to speed up tests and enable us to better structure our features without concern for lengthening our tests.
49+
We do not generally edit the test.py file in the test case resources scripts. This script is created by squish and
50+
handles starting up tests and setting up the hooks. This could be used to start up the client instead of using
51+
`@OnFeatureStart` to speed up tests and enable us to better structure our features without concern for lengthening
52+
our tests.
2953

3054
## Scenario and Feature hooks
3155

32-
In the script section of the test suite resources, there is a file named `bdd_hooks.py`. This file contains a number of functions hooked into the tests to run at the beginning and end of features. For example:
56+
In the script section of the test suite resources, there is a file named `bdd_hooks.py`. This file contains a number of
57+
functions hooked into the tests to run at the beginning and end of features. For example:
3358

3459
```python
3560
@OnFeatureStart
3661
def hook(context):
3762
do_hook_code()
3863
```
3964

40-
Before the scenarios of a feature are run this hook is called by Squish. We utilise `@OnFeatureStart`, `@OnScenarioStart`, `@OnScenarioEnd` and `@OnFeatureEnd` to carry out the test setup and cleanup activities. More details at `6.19.10. Performing Actions During Test Execution Via Hooks` of https://doc.froglogic.com/squish/latest/api.bdt.functions.html.
65+
Before the scenarios of a feature are run this hook is called by Squish. We utilise `@OnFeatureStart`,
66+
`@OnScenarioStart`, `@OnScenarioEnd` and `@OnFeatureEnd` to carry out the test setup and cleanup activities.
67+
More details at `6.19.10. Performing Actions During Test Execution Via Hooks` of
68+
https://doc.froglogic.com/squish/latest/api.bdt.functions.html.
4169

4270
## Implementing a new test
4371

44-
Have you already agreed to a gherkin description of the behaviour required? If so then add it to the test cases either as a new feature (there's a little button labelled BDD in the test cases section of the Squish GUI) or if your feature fits well into a feature already in the test suite then include the scenarios in there - this avoids running feature start and end code which restarts the client and lengthens the tests, though don't be afraid to add a new feature if it doesn't fit.
45-
46-
If you haven't already agreed on the behaviour, consider creating a design for the feature with gherkin and a low-fidelity prototype and reviewing it with other developers and script generator users - this depends on how major and well defined the feature is. If you're not sure, ask the team!
47-
48-
Now that you have your feature, scenario and steps laid out it's time to write the test code. Are any of the steps already defined in the test suite resources? They may not have the same name but they may have the same functionality - you can add a new `@Given`, `@When` or `@Then` decorator to the step or rename the step in the test case. Any steps that don't have an already defined test function for you will need to implement, these steps will be annotated by Squish in the test case.
49-
50-
To add the steps you want you can either code them directly by writing a test step function or you can record it. If you right-click on a feature or scenario in the test case and click `Record Missing Steps in Feature/Scenario` then the test will execute the steps it knows and then pauses on the steps it doesn't know to record any button clicks and do any verification steps as according to the squish recording tools - see the tutorial on https://www.froglogic.com/squish/features/recording-and-playback/. After recording, this will insert the step function into a file in the steps section of the test suite resources - often this is in a file that doesn't make sense so please move it to somewhere it does make sense.
51-
52-
Although the recording is useful, it often produces brittle step functions, please make use of the utilities in the global scripts area to improve the robustness of the test and see [here](System-Testing-with-Squish) for some hints, tips and gotchas.
72+
Have you already agreed to a gherkin description of the behaviour required? If so then add it to the test cases either
73+
as a new feature (there's a little button labelled BDD in the test cases section of the Squish GUI) or if your feature
74+
fits well into a feature already in the test suite then include the scenarios in there - this avoids running feature
75+
start and end code which restarts the client and lengthens the tests, though don't be afraid to add a new feature if
76+
it doesn't fit.
77+
78+
If you haven't already agreed on the behaviour, consider creating a design for the feature with gherkin and a
79+
low-fidelity prototype and reviewing it with other developers and script generator users - this depends on how major
80+
and well defined the feature is. If you're not sure, ask the team!
81+
82+
Now that you have your feature, scenario and steps laid out it's time to write the test code. Are any of the steps
83+
already defined in the test suite resources? They may not have the same name but they may have the same
84+
functionality - you can add a new `@Given`, `@When` or `@Then` decorator to the step or rename the step in the test
85+
case. Any steps that don't have an already defined test function for you will need to implement, these steps will be
86+
annotated by Squish in the test case.
87+
88+
To add the steps you want you can either code them directly by writing a test step function or you can record it.
89+
If you right-click on a feature or scenario in the test case and click `Record Missing Steps in Feature/Scenario` then
90+
the test will execute the steps it knows and then pauses on the steps it doesn't know to record any button clicks and
91+
do any verification steps as according to the squish recording tools - see the tutorial on
92+
https://www.froglogic.com/squish/features/recording-and-playback/. After recording, this will insert the step function
93+
into a file in the steps section of the test suite resources - often this is in a file that doesn't make sense so
94+
please move it to somewhere it does make sense.
95+
96+
Although the recording is useful, it often produces brittle step functions, please make use of the utilities in the
97+
global scripts area to improve the robustness of the test and see [here](System-Testing-with-Squish) for some hints, tips and gotchas.
5398

5499
## Running the tests
55100

56-
You can run the whole test suite with the play button located above the test cases next to the new BDD test case button. You can also run test cases with the run button next to the case in the case list. You can run features and scenarios by right-clicking and pressing run.
101+
You can run the whole test suite with the play button located above the test cases next to the new BDD test case button.
102+
You can also run test cases with the run button next to the case in the case list. You can run features and scenarios
103+
by right-clicking and pressing run.

doc/client/testing/Test-naming.md

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,47 @@
11
# Test naming
22

3-
When writing tests, it is important that the purpose and expected outcome of the test is clear from the name. This has several advantages:
3+
When writing tests, it is important that the purpose and expected outcome of the test is clear from the name.
4+
This has several advantages, for example:
45

56
- It helps other developers debug failing tests
67
- It helps clarify your own thoughts as to the purpose of the test
7-
- It defines the code itself by explicitly stating the expected interface. Ideally you should be able to reconstruct a functional class entirely from its tests
8-
- And more
8+
- It defines the code itself by explicitly stating the expected interface. Ideally you should be able to reconstruct a
9+
functional class entirely from its tests
910

10-
It isn't expected that all tests will follow this guide, many tests pre-date this guide. Sometimes as well, these guidelines may prove overly restrictive or add unnecessary bulk to the test name. As ever, discretion is advised, but be clear why you're not following the guidelines if you choose not to. For example "'Initializes_ok' is fine as a test name because I'm just checking that I can initialize the class" would be a bad reason.
11+
While new tests should aim to follow the conventions documented here, it is allowable to deviate in cases such as:
12+
- Older tests which predate this naming convention; although if you are doing significant refactoring, consider updating
13+
the old test names to match this convention.
14+
- Adding tests to existing/external code which uses a different convention; prefer to adopt the convention in the
15+
surrounding code for consistency.
16+
- The convention is too restrictive for a particular test. Use discretion here; only deviate from the guidelines if you
17+
have a strong reason to do so.
1118

12-
There are many test naming formats out there, each with pros and cons, and each with people who get far too passionate about their personal favourite. We have opted to go with the GIVEN_WHEN_THEN format.
19+
There are many test naming formats out there, each with pros and cons. We have opted to go with the
20+
[Given When Then format](https://martinfowler.com/bliki/GivenWhenThen.html). The given-when-then scheme is broadly
21+
comparable with other common test naming & structuring schemes such as arrange-act-assert, but with different names.
1322

14-
Test names should take the following form:
23+
**Test names should take the following form:**
1524

1625
```
1726
GIVEN_[pre-conditions]_WHEN_[action]_THEN_[result]
1827
```
1928

2029
GIVEN, WHEN, and THEN are in capitals with the rest of the test name in lower case, words are separated by underscores.
2130

22-
In some cases, there are no preconditions, or the preconditions are truly trivial (be wary of jumping to that conclusion though). In those cases given may be omitted.
31+
In cases where there are no preconditions, or where the preconditions are very simple, the "given" section may be
32+
omitted.
2333

24-
Where possible don't include the method being tested name in the test name as that could change over time.
34+
Where possible, don't include the method being tested name in the test name, as that could change over time.
2535

26-
Given that java methods usually use CamelCase, it is useful to tell CheckStyle to ignore the name format add a warning suppression to the top of the class:
36+
Given that java methods usually use CamelCase, it is useful to tell Checkstyle to ignore the name format add a warning
37+
suppression to the top of the class:
2738

39+
```java
40+
@SuppressWarnings({ "checkstyle:magicnumber", "checkstyle:methodname" })
41+
public class SomethingTest {
42+
@Test
43+
public void GIVEN_my_test_isnt_written_in_camel_case_WHEN_test_is_viewed_in_eclipse_THEN_checkstyle_does_not_issue_warning() {}
44+
}
2845
```
29-
@SuppressWarnings({ "checkstyle:magicnumber", "checkstyle:methodname" })
30-
public class GIVEN_my_test_isnt_written_in_camel_case_WHEN_test_is_viewed_in_eclipse_THEN_checkstyle_does_not_issue_warning {
31-
```
32-
33-
It may be worth adding the magic-number suppression too depending on the type of tests.
46+
47+
In some cases, the `checkstyle:magicnumber` suppression may also be helpful, depending on the type of tests.

0 commit comments

Comments
 (0)