This is an old revision of the document!
Writing tests
(Caution: this tutorial is currently under construction. Please come back tomorrow to see the complete version.)
Description: In this tutorial you will learn how to write unit (and not only) tests for your CRAM functions and features.
Previous Tutorial: Implementing failure handling for the TurtleSim
lisp-unit
The library we are going to use to write our unit tests is called lisp-unit
, it is one of the simplest ones out there for Common Lisp. There are more elaborate ones that can do more things but in most cases lisp-unit
is going to be more than enough for you.
For more information on the library check it's documentation page and the GitHub repo.
Setting up the test infrastructure
Let's create a new test asdf system, call it cram-my-beginner-tutorial-tests.asd
. It should be in the root of our ROS package, right next to cram-my-beginner-tutorial.asd
.
Put the following into the file:
(defsystem cram-my-beginner-tutorial-tests :depends-on (cram-my-beginner-tutorial lisp-unit roslisp geometry_msgs-msg) :components ((:module "tests" :components ((:file "package") (:file "simple-plans-tests" :depends-on ("package")))))) (defmethod asdf:perform ((o asdf:test-op) (c (eql (asdf:find-system 'cram-prolog-tests)))) (flet ((symbol (pkg name) (intern (string name) (find-package pkg)))) (funcall (symbol :cram-my-beginner-tutorial-tests :run-cram-my-beginner-tutorial-tests))))
Now let us load the test package and switch into its namespace. You might need to restart your Emacs at this point, because the new ASDF system might not be visible to it without restarting.
CL-USER> (ros-load:load-system "cram_my_beginner_tutorial" :cram-my-beginner-tutorial-tests) CL-USER> (in-package :tut-test)
Writing our own test for the beginner tutorial code
We are going to write some tests for the functions we wrote in the previous tutorials.
Let's see how to implement this.
(define-test ...