Hey everyone,
Just wanted to quickly share an open source project I've been working on: KUnit, a unit testing framework for KAREL. It provides some simple structures and assertions for writing automated unit tests on the controller.
I wrote a blog post about it here: Introducing KUnit
You can download and view the source code on GitHub: https://github.com/onerobotics/KUnit/
It basically allows you to write small tests/assertions about your KAREL code and then use a web browser to see the test output.
Example:
Code
PROGRAM test_add_int
-- %NOLOCKGROUP is required to run KAREL from browser
%NOLOCKGROUP
-- %INCLUDE the KUnit routines
%INCLUDE kunit.h
-- the ROUTINE under test
ROUTINE add_int(l : INTEGER; r : INTEGER) : INTEGER
BEGIN
RETURN(l + r)
END add_int
-- 1 + 1 = 2
ROUTINE test_11 : BOOLEAN
BEGIN
RETURN(kunit_eq_int(2, add_int(1,1)))
END test_11
-- 2 + 2 = 4
ROUTINE test_22 : BOOLEAN
BEGIN
RETURN(kunit_eq_int(4, add_int(2,2)))
END test_22
-- 0 + 0 = 0
ROUTINE test_00 : BOOLEAN
BEGIN
RETURN(kunit_eq_int(0, add_int(0,0)))
END test_00
BEGIN
-- initialize KUnit
kunit_init
-- do some tests
kunit_test('1+1=2', test_11)
kunit_test('2+2=4', test_22)
kunit_test('0+0=0', test_00)
-- output the test suite results
kunit_output
END test_add_int
Display More
Run the program in the browser via http://robot.ip.address/KAREL/test_add_int and see:
Code
KUnit
...
Finished in 0.002 seconds
1500.0 tests/sec, 1500.0 assertions/sec
3 tests, 3 assertions, 0 failures
Display More
Give it a shot and let me know if you have any questions, issues, feedback, feature requests, etc. Pull requests gladly accepted