| Homepage | Content | Slides | Video |
Warning
This lesson is under construction. Learn from it at your own risk. If you have any feedback, please fill out our General Feedback Survey.
def add_double(x, y):
return 2*(x+y)
def test_add_double():
expect(add_double(1, 2) == 6)
Most test are consist of the same general structure:
Simulating behavior external to a program so your tests can run independently of other platforms.
You’re testing your program, not somebody else’s. Mock other people’s stuff, not your own.
$ run tests
Finding tests...
Running tests in tests/foo.ext
Running tests in tests/bar.ext
Running tests in misc/test_baz.ext
While you can write tests the hard way:
var = some_function(x)
if var == expected_output:
continue
else
print("Test X failed!")
$ run test
Test 5 failed!
It’s usually easier to use a framework.
def simple_test():
expect(some_function(x), expected_output)
$ run tests
....x.....
Test 5 failed.
Debug information:
...
def tests_setup():
connect to database
populate database with test data
def tests_teardown():
delete all data from test database
disconnect from database
def some_test()
setup is called automaically
use data in database
asset something is true
teardown is run automatically