aboutsummaryrefslogtreecommitdiff
path: root/doc/testing.org
blob: c28444b2b318851736a662a00eb2a8be493efee0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#+TITLE: Testing GN2

* Table of Contents                                                     :TOC:
- [[#introduction][Introduction]]
- [[#run-tests][Run tests]]
  - [[#setup][Setup]]
  - [[#running][Running]]

* Introduction

For integration testing, we currently use [[https://github.com/genenetwork/genenetwork2/tree/testing/test/requests][Mechanica Rob]] against the
small [[https://github.com/genenetwork/genenetwork2/blob/testing/doc/database.org][database]]; a setup we call Mechanical Rob because it emulates
someone clicking through the website and checking results.

These scripts invoke calls to a running webserver and test the response.
If a page changes or breaks, tests will fail. In principle, Mechanical
Rob runs before code merges get committed to the main server.

For unit tests, we use python's =unittest= framework. Coverage reports
get generated using [[https://coverage.readthedocs.io/en/coverage-5.2.1/][coverage.py]] which you could also use to run
unit tests. When adding new functionality, it is advisable to add
unit tests.

* Run tests

** Setup

Everything required for testing is already package with guix:

: ./pre-ins-env guix package -i genenetwork2 -p ~/opt/genenetwork2

** Running

Run the tests from the root of the genenetwork2 source tree as. Ensure
that Redis and Mariadb are running.

To run Mechanical Rob:
: time env GN2_PROFILE=~/opt/genenetwork2 TMPDIR=~/tmp SERVER_PORT=5004 GENENETWORK_FILES=/gnu/data/gn2_data/ ./bin/genenetwork2 ./gn2/default_settings.py -c ~/projects/genenetwork2/test/requests/test-website.py -a http://localhost:5004

Use these aliases for the following examples.

#+begin_src sh
alias runpython="env GN2_PROFILE=~/opt/gn-latest TMPDIR=/tmp SERVER_PORT=5004 GENENETWORK_FILES=/gnu/data/gn2_data/ ./bin/genenetwork2"

alias runcmd="time env GN2_PROFILE=~/opt/gn-latest TMPDIR=//tmp SERVER_PORT=5004 GENENETWORK_FILES=/gnu/data/gn2_data/ ./bin/genenetwork2 ./gn2/default_settings.py -cli"
#+end_src

You could use them in your =.bashrc= or =.zshrc= file.

To run unit tests:

: runpython -m unittest discover -v

Or alternatively using the coverage tool:

: runcmd coverage run -m unittest discover -v

To generate a html coverage report in =wqflask/coverage_html_report/=

: runcmd coverage html

To output the report to =STDOUT=:

: runcmd coverage report

All the configs for running the coverage tool are in
=wqflask/.coveragerc=