|
1 | | -# Splunk Test "Framework" |
| 1 | +# Splunk Test Suite |
2 | 2 |
|
3 | | -The truth is that there really isn't a Splunk Test Framework. It simply uses |
4 | | -Python's builtin unittest module. |
| 3 | +The test suite uses Python's standard library and the built-in **unittest** |
| 4 | +library. If you're using Python 2.7, you're all set. However, if you are using |
| 5 | +Python 2.6, you'll also need to install the **unittest2** library to get the |
| 6 | +additional features that were added to Python 2.7 (just run `pip install |
| 7 | +unittest2` or `easy_install unittest2`). |
5 | 8 |
|
6 | | -Each distinct area of the SDK is tested in a single file. For example, |
7 | | -roles are tested in `test_role.py`, while the examples are tested |
8 | | -in `test_examples.py`. |
| 9 | +To run the unit tests, open a command prompt in the **/splunk-sdk-python** |
| 10 | +directory and enter: |
9 | 11 |
|
10 | | -Before running the test suite, make sure the instance of Splunk you |
| 12 | + python setup.py test |
| 13 | + |
| 14 | +You can also run individual test files, which are located in |
| 15 | +**/splunk-sdk-python/tests**. Each distinct area of the SDK is tested in a |
| 16 | +single file. For example, roles are tested |
| 17 | +in `test_role.py`. To run this test, open a command prompt in |
| 18 | +the **/splunk-sdk-python/tests** subdirectory and enter: |
| 19 | + |
| 20 | + python test_role.py |
| 21 | + |
| 22 | +NOTE: Before running the test suite, make sure the instance of Splunk you |
11 | 23 | are testing against doesn't have new events being dumped continuously |
12 | 24 | into it. Several of the tests rely on a stable event count. It's best |
13 | | -to test against a clean install of Splunk, but if you cannot, you |
| 25 | +to test against a clean install of Splunk, but if you can't, you |
14 | 26 | should at least disable the *NIX and Windows apps. Do not run the test |
15 | 27 | suite against a production instance of Splunk! It will run just fine |
16 | | -with the free Splunk license, so don't be stingy with instances. |
17 | | - |
18 | | -You also need to install the `sdk-app-collection` app in your instance of |
19 | | -Splunk. The `sdk-app-collection` is a set of small, single purpose apps |
20 | | -for testing capabilities that cannot be created with the REST API.You can |
21 | | -fetch it from `https://github.com/splunk/sdk-app-collection`. Put the |
22 | | -whole repository in `$SPLUNK_HOME/etc/apps`, so the git root would be |
23 | | -`$SPLUNK_HOME/etc/apps/sdk-app-collection`. |
24 | | - |
25 | | -If you are running Python 2.6, you must install the `unittest2` library, |
26 | | -since the test suite depends on features added to `unittest` in Python 2.7. |
27 | | -Python 2.7 should run the test suite using only Python's standard library. |
28 | | - |
29 | | -The test suite depends on nothing but Python's standard library. You can |
30 | | -simply execute: |
| 28 | +with the free Splunk license. |
31 | 29 |
|
32 | | - python setup.py test |
33 | | - |
34 | | -or run the test_all.py script in the tests/ directory. |
35 | 30 |
|
36 | 31 | ## Code Coverage |
37 | 32 |
|
38 | | -We have support for using the excellent `coverage.py`, which needs to be |
39 | | -installed on your system. You can get more information about the module |
40 | | -at the author's website: http://nedbatchelder.com/code/coverage/ |
| 33 | +Coverage.py is an excellent tool for measuring code coverage of Python programs. |
41 | 34 |
|
42 | | -To install it, simply use `easy_install` or `pip`: |
| 35 | +To install it, use easy_install: |
43 | 36 |
|
44 | | - pip install coverage |
| 37 | + easy_install coverage |
45 | 38 |
|
46 | | -or |
| 39 | +Or use pip: |
47 | 40 |
|
48 | | - easy_install coverage |
| 41 | + pip install coverage |
49 | 42 |
|
50 | | -Once you have `coverage.py` installed, you can run get coverage information |
51 | | -as follows: |
| 43 | +To generate a report of the code coverage of the unit test suite, open a command |
| 44 | +prompt in the **/splunk-sdk-python** directory and enter: |
52 | 45 |
|
53 | 46 | python setup.py coverage |
54 | 47 |
|
55 | | -This will create an HTML report in coverage_html/. Open `coverage_html/index.html` |
56 | | -in your favorite browser to see the coverage report. |
| 48 | +This command runs the entire test suite and writes an HTML coverage report to |
| 49 | +the **/splunk-sdk-python/coverage_report** directory. |
| 50 | + |
| 51 | +For more information about Coverage.py, see the author's website |
| 52 | +([http://nedbatchelder.com/code/coverage/](http://nedbatchelder.com/code/coverage/)). |
0 commit comments