the test
module has some assertion functions to testing.
assert
functionthis function is a function in the pashmak. this function gets a value and asserts that is true:
# NOTE: you don't need to import anything for use this function
assert(2 == 2) # ok
assert(4 > 1) # ok
assert(True) # ok
assert('foo' == 'bar') # error: AssertError
asserts true:
import @test
test.assertTrue(True)
test.assertTrue(5 == 5)
test.assertTrue(10 > 5)
above code will be run without error.
this code will get AssertError
:
test.assertTrue(False)
test.assertTrue(3 == 2)
this function is reverse of test.assertTrue
.
test.assertFalse(False) # run be run without error
test.assertFalse(3 == 2) # run be run without error
test.assertFalse(2 == 2) # AssertionError
this function asserts two values equals.
# two arguments should be passed:
test.assertEquals('hello', 'hello') # successful
test.assertEquals(2, 2) # successful
test.assertEquals('foo', 'bar') # AssertionError
this function is reverse of test.assertEquals
.
test.assertNotEquals('foo', 'bar') # successful
test.assertNotEquals(2, 7) # successful
test.assertNotEquals(2, 2) # AssertionError
asserts the value is empty(null).
test.assertEmpty(null)
test.assertEmpty('hello') # error
asserts value is not empty(null).
test.assertNotEmpty('hello')
test.assertNotEmpty(null) # error