Skip to main content

A simple unit testing framework for Python 3.

Project description

VSUT is a simple unit test framework for Python.

Usage

A unit can be described , like follows:

...
class UnitTest(vsut.unit.Unit):

    def testComponentOne(self):
        ...
    def testComponentTwo(self):
        ...

Any methods that start with ‘test’ will be executed automatically, once the case is run.

Asserts & Fail Conditions

The following methods can be used in a test-case to check for success or failure:

  • assertEqual(expected, actual) - Checks for equality of the two arguments.

  • assertNotEqual(expected, actual) - Checks for inequality of the two arguments.

  • assertTrue(expected) - Checks whether the argument is the boolean value True.

  • assertFalse(expected) - Checks whether the argument is the boolean value False.

  • assertIn(expected, collection) - Checks whether the argument is in the collection.

  • assertNotIn(expected, collection) - Checks whether the argument is not in the collection.

  • assertIs(expected, actual) - Checks whether the value is the expected.

  • assertIsNot(expected, actual) - Checks whether the value is not the expected.

  • assertIsNone(expected) - Checks whether the argument is None.

  • assertIsNotNone(expected) - Checks whether the argument is not None.

  • assertRaises(exception, func, *args) - Checks whether the function ‘func’ raises an exception of the type ‘exception’.

For any of these methods a message parameter can be specified, that will be printed instead of the default message.

Example

...
assertEqual(True, False, message="True is not False")
...

Full Example

from vsut.unit import Unit
from vsut.assertion import assertEqual

class TestCase(Unit):

    def testExample(self):
        a = True
        b = True
        c = False
        assertEqual(a, b)
        assertEqual(b, c)

Running units

Units can be run with the test runner, as follows:

python runner.py [--format=table] module.TestClass module1.TestClass1 ...
The --format argument is optional and specifies the method of formatting the output. Available methods are table and csv, with table being the default.
The separator for the csv-data can be specified with the parameter --separator.

NOTE: Some characters require escaping with \, as they are special characters.

Output as Table

Output as a table can look like this for example:
```
[TestCase]
Id | Name | Status | Time | Assert | Message
0 | testAssertEqual | OK | 0.000003 | |
1 | testAssertEqualFail | OK | 0.000008 | |
2 | testAssertFalse | OK | 0.000001 | |
3 | testAssertIn | OK | 0.000002 | |
4 | testAssertIs | OK | 0.000001 | |
5 | testAssertIsNone | OK | 0.000002 | |
6 | testAssertIsNot | OK | 0.000001 | |
7 | testAssertIsNotNone | OK | 0.000001 | |
8 | testAssertNotEqual | OK | 0.000001 | |
9 | testAssertNotIn | OK | 0.000002 | |
10 | testAssertRaises | OK | 0.000005 | |
11 | testAssertTrue | OK | 0.000002 | |
12 | testFailWithCustomMessage | FAIL | 0.000003 | assertEqual | A custom message.
13 | testWillFail | FAIL | 0.000003 | assertEqual | 1 != 2
14 | testWillFailToo | FAIL | 0.000003 | assertNotEqual | 1 == 1
#### Output as CSV
Output as CSV can look like this for example:
TestCase
0,testAssertEqual,OK,0.000004
1,testAssertEqualFail,OK,0.000011
2,testAssertFalse,OK,0.000002
3,testAssertIn,OK,0.000004
4,testAssertIs,OK,0.000004
5,testAssertIsNone,OK,0.000002
6,testAssertIsNot,OK,0.000004
7,testAssertIsNotNone,OK,0.000002
8,testAssertNotEqual,OK,0.000003
9,testAssertNotIn,OK,0.000002
10,testAssertRaises,OK,0.000007
11,testAssertTrue,OK,0.000003
12,testFailWithCustomMessage,FAIL,0.000006,assertEqual,A custom message.
13,testWillFail,FAIL,0.000007,assertEqual,1 != 2
14,testWillFailToo,FAIL,0.000006,assertNotEqual,1 == 1
```

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vsut-1.5.1.tar.gz (6.9 kB view details)

Uploaded Source

File details

Details for the file vsut-1.5.1.tar.gz.

File metadata

  • Download URL: vsut-1.5.1.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for vsut-1.5.1.tar.gz
Algorithm Hash digest
SHA256 3c7e7943b39b55343e7af9bdc49d89fab14e42ce386b2414d77c8a911cf3e9cd
MD5 5d78a622b517f622ea8dbfa83cbd66a3
BLAKE2b-256 3a2d7b6348e59ab645a9fad55635362f07c4faab433b59ebddea0c5c9cdec7c0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page