1 Attachment(s)
Test Driven Development & Unit Testing for thinBASIC
Thanks to my colleague Honza, I discovered the interesting world of Test Driven Development.
It is a topic for fat book, but let's sum it up quickly:
- test driven development is approach to write safe code with predicable output
- it is based on idea of writing failing tests first and implementing functionality later, to remove the errors step by step
While I hope we will be able to put together built in Unit Testing system with Eros (for ThinBASIC 2.x), let's experiment now!
I prepaired simple unitTesting.tBasicU, which covers most of the needs for TDD beginner (bold statement, ain't it).
It features engine for setting up the tests:
- ut_Initialize
- ut_LaunchTests
- ut_SaveLog
- ut_Release
- ut_GetLastError
Many pre-defined asserts for typical cases:
- ut_assertEqual
- ut_assertEqualRounded
- ut_assertEqualEpsilon
- ut_assertNotEqual
- ut_assertEqualText
- ut_assertNotEqualText
- ut_assertIsGreater
- ut_assertIsLess
- ut_assertIsTrue
- ut_assertIsFalse
- ut_assertIsNull
- ut_assertIsNotNull
- ut_assertIsEmpty
- ut_assertIsNotEmpty
- ut_assertError
And set of functions to retrieve the test results immediately:
- ut_GetFailureCount
- ut_GetFailureTestName
- ut_GetFailureAssertType
- ut_GetFailureDescription
- ut_GetFailureComment
The test functions should be prefixed with test_, with two specific cases:
- test_SetUp - launched before each test
- test_TearDown - launched after each test
Confused? What does it mean? What is it good for?
Let's have a look at example in my next post.
Petr