You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/code/Writing_Tests/RunUnitTests.md
+58-5Lines changed: 58 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,13 +1,49 @@
1
-
2
1
# How to run MPF unittests
3
2
4
-
Once MPF is installed, you can run some automated tests to make sure that everything is working. To do this, open a command prompt, and then type the following command and then press <enter>:
3
+
Once MPF is installed, you can run some automated tests to make sure that everything is working.
4
+
Let's assume your mpf virtual folder is `mpfenv` and stored here
5
+
6
+
Windows:
7
+
```console
8
+
C:\Users\myname\mpfenv
9
+
```
10
+
Linux:
11
+
```console
12
+
/home/myname/mpfenv
13
+
```
14
+
Note that you need to activate your virtual environment to run tests the same way you do to run your game. Assuming you are in your users home directory, run:
15
+
16
+
Windows:
17
+
```console
18
+
mpfenv\Scripts\activate.bat
19
+
```
20
+
Linux:
21
+
```console
22
+
mpfenv/bin/activate
23
+
```
24
+
Now change into the directory where the tests are stored in your console, which is:
You might have a different version of python and your path might differ slightly.
35
+
Now you have different options on how to run the tests. You can either run all tests at once, or only all tests in one test file or only one single test. Which option is best for you depends on your needs.
36
+
37
+
## Running all tests at once
9
38
10
-
When you do this, you should see a bunch of dots on the screen (one for each test that’s run), and then when it’s done, you should see a message showing how many tests were run and that they were successful. The whole process should take less a minute or so.
39
+
To do this, open a command prompt, and then type the following command and then press `<enter>`:
40
+
41
+
```console
42
+
python3 -m unittest discover <path to test directory>
43
+
```
44
+
Where `<path to test directory>` is the path to the directory where you tests are stored. If you have followed the steps above you are already in that directory and you just omit this value.
45
+
46
+
You should see a bunch of dots on the screen (one for each test that’s run), and then when it’s done, you should see a message showing how many tests were run and that they were successful. The whole process should take less a minute or so.
11
47
12
48
(If you see any messages about some tests taking more than 0.5s, that’s ok.)
13
49
@@ -25,6 +61,24 @@ Note that the number of tests is changing all the time, so it probably won’t b
25
61
26
62
These tests are the actual tests that the developers of MPF use to test MPF itself. We wrote all these tests to make sure that updates and changes we add to MPF don’t break things. :) So if these tests pass, you know your MPF installation is solid.
27
63
64
+
## Running all test of a single test file
65
+
If you have the need only to test all tests in a single test file you can specify the test file in your directory
66
+
```console
67
+
python -m unittest test_SegmentDisplay.py
68
+
```
69
+
That obviously runs all tests in the file called `test_SegmentDisplay.py`, which makes sense to save time if your code changes only took place in that part of the code.
70
+
71
+
## Running a single test
72
+
If only one test fails and you need to execute it more often you can even specify only that one single test
python -m unittest <file name without py extension>.<Class name within file>.<name of test>
79
+
```
80
+
81
+
## Testing the MPF media controller
28
82
Remember though that MPF is actually two separate parts, the MPF game engine and the MPF media controller. The command you run just tested the game engine, so now let’s test the media controller. To do this, run the following command (basically the same thing as last time but with an “mc” added to the end, like this):
29
83
30
84
```console
@@ -42,4 +96,3 @@ Notes about the MPF-MC tests:
42
96
* These tests create a window on the screen and then just re-use the same window for all tests (to save time). So don’t worry if it looks like the window content is scaled weird or blurry or doesn’t fill the entire window.
43
97
* Many of these tests are used to test internal workings of the media controller itself, so there will be lots of time when the pop up window is blank or appears frozen since the tests are testing non-visual things.
44
98
* The animation and transition tests include testing functionality to stop, restart, pause, and skip frames. So if things look “jerky” in the tests, don’t worry, that doesn’t mean your computer is slow, it’s just how the tests work! :)
0 commit comments