mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Merge pull request #965 from bigchaindb/move-all-runtests-docs-to-one-place
Consolidated all tests-related docs in one place
This commit is contained in:
commit
8fa6789745
@ -28,7 +28,8 @@ To contribute code or documentation, you need a [GitHub account](https://github.
|
||||
|
||||
Familiarize yourself with how we do coding and documentation in the BigchainDB project, including:
|
||||
|
||||
* [our Python Style Guide](PYTHON_STYLE_GUIDE.md) (includes how we write tests)
|
||||
* [our Python Style Guide](PYTHON_STYLE_GUIDE.md)
|
||||
* [how we write and run tests](./tests/README.md)
|
||||
* [our documentation strategy](./docs/README.md) (including in-code documentation)
|
||||
* the GitHub Flow (workflow)
|
||||
* [GitHub Guide: Understanding the GitHub Flow](https://guides.github.com/introduction/flow/)
|
||||
@ -103,7 +104,7 @@ git checkout -b new-branch-name
|
||||
With your new branch checked out locally, make changes or additions to the code or documentation. Remember to:
|
||||
|
||||
* follow [our Python Style Guide](PYTHON_STYLE_GUIDE.md).
|
||||
* write and run tests for any new or changed code. There's a section in [our Python Style Guide](PYTHON_STYLE_GUIDE.md) about writing and running tests.
|
||||
* write and run tests for any new or changed code. There's [a README file in the `tests/` folder](./tests/README.md) about how to do that.
|
||||
* add or update documentation as necessary. Follow [our documentation strategy](./docs/README.md).
|
||||
|
||||
As you go, git add and git commit your changes or additions, e.g.
|
||||
@ -119,7 +120,7 @@ git fetch upstream
|
||||
git merge upstream/master
|
||||
```
|
||||
|
||||
Once you're done commiting a set of new things and you're ready to submit them for inclusion, please be sure to run all the tests (as per the instructions at the end of our [Python Style Guide](PYTHON_STYLE_GUIDE.md)).
|
||||
Once you're done commiting a set of new things and you're ready to submit them for inclusion, please be sure to run all the tests as per the instructions in [the README file in the `tests/` folder](./tests/README.md).
|
||||
|
||||
(When you submit your pull request [following the instructions below], we run all the tests automatically, so we will see if some are failing. If you don't know why some tests are failing, you can still submit your pull request, but be sure to note the failing tests and to ask for help with resolving them.)
|
||||
|
||||
|
@ -65,7 +65,7 @@ x = 'name: {}; score: {}'.format(name, n)
|
||||
we use the `format()` version. The [official Python documentation says](https://docs.python.org/2/library/stdtypes.html#str.format), "This method of string formatting is the new standard in Python 3, and should be preferred to the % formatting described in String Formatting Operations in new code."
|
||||
|
||||
|
||||
## Runnng the Flake8 Style Checker
|
||||
## Running the Flake8 Style Checker
|
||||
|
||||
We use [Flake8](http://flake8.pycqa.org/en/latest/index.html) to check our Python code style. Once you have it installed, you can run it using:
|
||||
```text
|
||||
@ -75,48 +75,6 @@ flake8 --max-line-length 119 bigchaindb/
|
||||
|
||||
## Writing and Running (Python) Tests
|
||||
|
||||
We write unit and integration tests for our Python code using the [pytest](http://pytest.org/latest/) framework.
|
||||
The content of this section was moved to [`bigchiandb/tests/README.md`](./tests/README.md).
|
||||
|
||||
All tests go in the `bigchaindb/tests` directory or one of its subdirectories. You can use the tests already in there as templates or examples.
|
||||
|
||||
You can run all tests using:
|
||||
```text
|
||||
py.test -v
|
||||
```
|
||||
|
||||
or, if that doesn't work, try:
|
||||
```text
|
||||
python -m pytest -v
|
||||
```
|
||||
|
||||
or:
|
||||
```text
|
||||
python setup.py test
|
||||
```
|
||||
|
||||
If you want to learn about all the things you can do with pytest, see [the pytest documentation](http://pytest.org/latest/).
|
||||
|
||||
### Tox
|
||||
|
||||
We use [tox](https://tox.readthedocs.io/en/latest/) to run multiple suites of tests against multiple environments during automated testing. Generally you don't need to run this yourself, but it might be useful when troubleshooting a failing CI build.
|
||||
|
||||
To run all the tox tests, use:
|
||||
```text
|
||||
tox
|
||||
```
|
||||
|
||||
or:
|
||||
```text
|
||||
python -m tox
|
||||
```
|
||||
|
||||
To run only a few environments, use the `-e` flag:
|
||||
```text
|
||||
tox -e {ENVLIST}
|
||||
```
|
||||
|
||||
where `{ENVLIST}` is one or more of the environments specified in the [tox.ini file](tox.ini).
|
||||
|
||||
### Automated testing of pull requests
|
||||
|
||||
We use [Travis CI](https://travis-ci.com/), so that whenever someone creates a new BigchainDB pull request on GitHub, Travis CI gets the new code and does _a bunch of stuff_. You can find out what we tell Travis CI to do in [the `.travis.yml` file](.travis.yml): it tells Travis CI how to install BigchainDB, how to run all the tests, and what to do "after success" (e.g. run `codecov`). (We use [Codecov](https://codecov.io/) to get a rough estimate of our test coverage.)
|
||||
Note: We automatically run all tests on all pull requests (using Travis CI), so you should definitely run all tests locally before you submit a pull request. See the above-linked README file for instructions.
|
@ -5,4 +5,4 @@ Develop & Test BigchainDB Server
|
||||
:maxdepth: 1
|
||||
|
||||
setup-run-node
|
||||
running-unit-tests
|
||||
running-all-tests
|
||||
|
3
docs/server/source/dev-and-test/running-all-tests.md
Normal file
3
docs/server/source/dev-and-test/running-all-tests.md
Normal file
@ -0,0 +1,3 @@
|
||||
# Running All Tests
|
||||
|
||||
All documentation about writing and running tests (unit and integration tests) was moved to [the file `bigchaindb/tests/README.md`](https://github.com/bigchaindb/bigchaindb/blob/master/tests/README.md).
|
@ -1,36 +0,0 @@
|
||||
# Running Unit Tests
|
||||
|
||||
Once you've installed BigchainDB Server, you may want to run all the unit tests. This section explains how.
|
||||
|
||||
First of all, if you installed BigchainDB Server using `pip` (i.e. by getting the package from PyPI), then you didn't install the tests. **Before you can run all the unit tests, you must [install BigchainDB from source](setup-run-node.html#how-to-install-bigchaindb-from-source).**
|
||||
|
||||
To run all the unit tests, first make sure you have RethinkDB running:
|
||||
|
||||
```text
|
||||
$ rethinkdb
|
||||
```
|
||||
|
||||
then in another terminal, do:
|
||||
|
||||
```text
|
||||
$ python setup.py test
|
||||
```
|
||||
|
||||
(Aside: How does the above command work? The documentation for [pytest-runner](https://pypi.python.org/pypi/pytest-runner) explains. We use [pytest](http://docs.pytest.org/en/latest/) to write all unit tests.)
|
||||
|
||||
|
||||
### Using docker-compose to Run the Tests
|
||||
|
||||
You can also use `docker-compose` to run the unit tests.
|
||||
|
||||
Start `RethinkDB` in the background:
|
||||
|
||||
```text
|
||||
$ docker-compose up -d rdb
|
||||
```
|
||||
|
||||
then run the unit tests using:
|
||||
|
||||
```text
|
||||
$ docker-compose run --rm bdb py.test -v
|
||||
```
|
@ -50,6 +50,9 @@ Build the images:
|
||||
docker-compose build
|
||||
```
|
||||
|
||||
**Note**: If you're upgrading BigchainDB and have previously already built the images, you may need
|
||||
to rebuild them after the upgrade to install any new dependencies.
|
||||
|
||||
Start RethinkDB:
|
||||
|
||||
```bash
|
||||
|
@ -1,18 +1,99 @@
|
||||
# Tests
|
||||
# BigchainDB Server Tests
|
||||
|
||||
## Test Structure
|
||||
## The tests/ Folder
|
||||
|
||||
Generally all tests are meant to be unit tests, with the exception of those in the [`integration/` folder](./integration/).
|
||||
The `tests/` folder is where all the tests for BigchainDB Server live. Most of them are unit tests. Integration tests are in the [`tests/integration/` folder](./integration/).
|
||||
|
||||
A few notes:
|
||||
|
||||
- [`common/`](./common/) contains self-contained tests only testing
|
||||
- [`tests/common/`](./common/) contains self-contained tests only testing
|
||||
[`bigchaindb/common/`](../bigchaindb/common/)
|
||||
- [`db/`](./db/) contains tests requiring the database backend (e.g. RethinkDB)
|
||||
- [`tests/db/`](./db/) contains tests requiring the database backend (e.g. RethinkDB)
|
||||
|
||||
## Pytest Customizations
|
||||
|
||||
Customizations we've added to `pytest`:
|
||||
## Writing Tests
|
||||
|
||||
- `--database-backend`: Defines the backend to use for the tests. Must be one of the backends
|
||||
available in the [server configuration](https://docs.bigchaindb.com/projects/server/en/latest/server-reference/configuration.html)
|
||||
We write unit and integration tests for our Python code using the [pytest](http://pytest.org/latest/) framework. You can use the tests in the `tests/` folder as templates or examples.
|
||||
|
||||
|
||||
## Running Tests
|
||||
|
||||
### Running Tests Directly
|
||||
|
||||
If you installed BigchainDB Server using `pip install bigchaindb`, then you didn't install the tests. Before you can run all the tests, you must install BigchainDB from source. The [`CONTRIBUTING.md` file](../CONTRIBUTING.md) has instructions for how to do that.
|
||||
|
||||
Next, make sure you have RethinkDB running in the background (e.g. using `rethinkdb --daemon`).
|
||||
|
||||
Now you can run all tests using:
|
||||
```text
|
||||
py.test -v
|
||||
```
|
||||
|
||||
or, if that doesn't work, try:
|
||||
```text
|
||||
python -m pytest -v
|
||||
```
|
||||
|
||||
or:
|
||||
```text
|
||||
python setup.py test
|
||||
```
|
||||
|
||||
How does `python setup.py test` work? The documentation for [pytest-runner](https://pypi.python.org/pypi/pytest-runner) explains.
|
||||
|
||||
The `pytest` command has many options. If you want to learn about all the things you can do with pytest, see [the pytest documentation](http://pytest.org/latest/). We've also added a customization to pytest:
|
||||
|
||||
`--database-backend`: Defines the backend to use for the tests.
|
||||
It must be one of the backends available in the [server configuration](https://docs.bigchaindb.com/projects/server/en/latest/server-reference/configuration.html).
|
||||
|
||||
|
||||
### Running Tests with Docker Compose
|
||||
|
||||
You can also use [Docker Compose](https://docs.docker.com/compose/) to run all the tests.
|
||||
|
||||
First, start `RethinkDB` in the background:
|
||||
|
||||
```text
|
||||
$ docker-compose up -d rdb
|
||||
```
|
||||
|
||||
then run the tests using:
|
||||
|
||||
```text
|
||||
$ docker-compose run --rm bdb py.test -v
|
||||
```
|
||||
|
||||
If you've upgraded to a newer version of BigchainDB, you might have to rebuild the images before
|
||||
being able to run the tests. Run:
|
||||
|
||||
```text
|
||||
$ docker-compose build
|
||||
```
|
||||
|
||||
to rebuild all the images (usually you only need to rebuild the `bdb` image).
|
||||
|
||||
## Automated Testing of All Pull Requests
|
||||
|
||||
We use [Travis CI](https://travis-ci.com/), so that whenever someone creates a new BigchainDB pull request on GitHub, Travis CI gets the new code and does _a bunch of stuff_. You can find out what we tell Travis CI to do in [the `.travis.yml` file](.travis.yml): it tells Travis CI how to install BigchainDB, how to run all the tests, and what to do "after success" (e.g. run `codecov`). (We use [Codecov](https://codecov.io/) to get a rough estimate of our test coverage.)
|
||||
|
||||
|
||||
### Tox
|
||||
|
||||
We use [tox](https://tox.readthedocs.io/en/latest/) to run multiple suites of tests against multiple environments during automated testing. Generally you don't need to run this yourself, but it might be useful when troubleshooting a failing Travis CI build.
|
||||
|
||||
To run all the tox tests, use:
|
||||
```text
|
||||
tox
|
||||
```
|
||||
|
||||
or:
|
||||
```text
|
||||
python -m tox
|
||||
```
|
||||
|
||||
To run only a few environments, use the `-e` flag:
|
||||
```text
|
||||
tox -e {ENVLIST}
|
||||
```
|
||||
|
||||
where `{ENVLIST}` is one or more of the environments specified in the [tox.ini file](../tox.ini).
|
||||
|
Loading…
x
Reference in New Issue
Block a user