March 25, 2019, 02:12:55 PM
Robotforum | Industrial Robots Community

 KAREL unit testing framework

Author Topic:  KAREL unit testing framework  (Read 2900 times)

0 Members and 1 Guest are viewing this topic.

March 01, 2014, 04:19:26 PM
Read 2900 times
Offline

jay


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: [Select]
  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

Run the program in the browser via http://robot.ip.address/KAREL/test_add_int and see:
Code: [Select]
KUnit

...

Finished in 0.002 seconds
1500.0 tests/sec, 1500.0 assertions/sec

3 tests, 3 assertions, 0 failures

Give it a shot and let me know if you have any questions, issues, feedback, feature requests, etc. Pull requests gladly accepted :)
« Last Edit: March 01, 2014, 06:30:13 PM by jay »

Today at 02:12:55 PM
Reply #1

Advertisement

Guest


Share via facebook Share via linkedin Share via pinterest Share via reddit Share via twitter

xx
KRC2/KRC4 update .Net Framework / KukavarProxy

Started by lionpeloux on KUKA Robot Forum

2 Replies
274 Views
Last post February 20, 2019, 12:46:58 PM
by lionpeloux
clip
testing X41 inputs

Started by Mechatronics_Godfather on KUKA Robot Forum

1 Replies
158 Views
Last post January 22, 2019, 10:58:58 AM
by Ayoub
xx
Software for testing Moduls?

Started by DragosM on ABB Robot Forum

1 Replies
1366 Views
Last post June 23, 2014, 03:46:07 PM
by hermann
xx
Stress testing of a gripper system

Started by newtom66 on KUKA Robot Forum

3 Replies
1017 Views
Last post June 12, 2017, 04:10:47 PM
by panic mode