-
-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: simple index + add docs on test / docker (#8181)
- do not copy README as index anymore (too confusing) - have a specific sleek index.md instead - publish doc on makefile targets for docker - add a doc on writing and running tests fixes: - #8104
- Loading branch information
Showing
9 changed files
with
144 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
# How to write and run tests | ||
|
||
If you are a developer you are really encouraged to write tests as you fix bug or develop new features. | ||
|
||
Having a test is also a good way to debug a particular piece of code. | ||
|
||
We would really love to see our test coverage augment. | ||
|
||
If you are new to tests, please read: | ||
- [something about test pyramid](https://automationstepbystep.com/2020/05/02/what-is-a-test-pyramid/) to understand importance of unit tests and integration tests | ||
- [perldoc on test](https://perldoc.perl.org/Test) | ||
- [Test::More module doc](https://perldoc.perl.org/Test::More) | ||
|
||
|
||
## Helpers | ||
|
||
We have some helpers for tests. | ||
|
||
See mainly: | ||
* [Test.pm](https://openfoodfacts.github.io/openfoodfacts-server/dev/ref-perl-pod/ProductOpener/Test.html) (notably `init_expected_results` and `compare_to_expected_results`) | ||
* [TestAPI.pm](https://openfoodfacts.github.io/openfoodfacts-server/dev/ref-perl-pod/ProductOpener/APITest.html) | ||
|
||
and other modules with Test in their name ! | ||
|
||
|
||
## Unit and Integration tests | ||
|
||
Unit tests are located in `tests/unit/`. | ||
|
||
Integration tests are in `tests/integration/`. | ||
|
||
Most integration tests issue queries to an open food facts | ||
|
||
## Integration with docker-compose | ||
|
||
Using Makefile targets, tests are run | ||
* with a specific `COMPOSE_PROJECT_NAME° to avoid crashing your development data while running tests (as the project name [changes container, network and volumes names](https://docs.docker.com/compose/environment-variables/envvars/#compose_project_name)) | ||
* with a specific expose port for Mongodb, to avoid clashes with dev instance. | ||
|
||
## Writing tests | ||
|
||
You can read other tests to understand how we write them (inspire yourself from recently created tests). | ||
|
||
One effective way is to create a list of tests each represented by a hashmap with inputs and expected outputs and run them in a loop. Add an `id` and/or a `desc` (description) and use it as last argument to check functions (like `ok`, `is`, …) to easily see tests running and identify failing tests. | ||
|
||
If your outputs are consequent, you might use json files (one per tests), stored on disk. See tests using `init_expected_results` (and see below to refresh those files). | ||
|
||
|
||
## Running tests | ||
|
||
The best way to run all test is to run: | ||
|
||
```bash | ||
make tests | ||
``` | ||
|
||
To run a single test you can use: | ||
|
||
* for unit test: | ||
```bash | ||
make unit-test test="filename.t" | ||
``` | ||
* for integration test: | ||
```bash | ||
make int-test test="filename.t" | ||
``` | ||
|
||
If you made change that impact stored expected results, you can use: | ||
|
||
* to re-generate all expected results: | ||
```bash | ||
make update_tests_results | ||
``` | ||
* or to generate expected results for a single test | ||
(here for integration test, `unit-test` otherwise) | ||
```bash | ||
make int-test="filename.t --update-expected results" | ||
``` | ||
|
||
If you re-generate test results, be sure to look carefully that the changes your commit are expected changes. | ||
|
||
|
||
## Debugging with tests | ||
|
||
Launching a test is a very effective way to understand what's going on in the code using the debugger. | ||
|
||
This is done calling the test with `perl -d`. | ||
You can also use "args" argument with make target: | ||
|
||
```bash | ||
make test-unit test="my-test.t" args="-d" | ||
``` | ||
|
||
Most of the time, you will have to use the next command "n" four times, before landing in you test, where you can easily set a breakpoint with `b <line-number>`. | ||
|
||
Read [perldoc about debugger](https://perldoc.perl.org/perldebug) to learn. more. | ||
|
||
|
||
> :pencil: Note: With this explanation, in integration tests that issue requests to the server, you won't be able to run the debugger inside the server code, only in the test. | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Reference Docker / Makefile commands | ||
|
||
<!-- | ||
DO NOT MODIFY this file it is overwritten by the above fine at compile time | ||
--> | ||
|
||
See [README in `docker` folder](../../docker/README.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Product Opener (Open Food Facts web server) documentation | ||
|
||
Welcome to the documentation of **Product Opener**, the web server at the heart of **[Open Food Facts](https://world.openfoodfacts.org/)** project. | ||
|
||
It also powers the sibling **Open \[[Beauty](https://world.openbeautyfacts.org/)|[Pet Food](https://world.openpetfoodfacts.org/)|[Products](https://world.openproductsfacts.org/)\] Facts** projects | ||
|
||
* If you want to use the API or are interested in the data, look at [API documentation](api/index.md) | ||
|
||
* If you are a developer, look at [Developer documentation](dev/index.md) | ||
|
||
The repository for the project is at https://github.com/openfoodfacts/openfoodfacts-server/ | ||
|
||
Do not hesitate to contribute to this documentation, this is highly appreciated. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters