Unit tests

From Second Life Wiki
Revision as of 17:04, 25 June 2009 by Poppy Linden (talk | contribs) (→‎Project-level C++ unit tests)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Why unit test?

To reduce the amount of risk associated with refactoring legacy code, and to prove the functionality and interface of new code, use unit tests.

In an environment where the code base is highly interdependent, rapidly changing, and expected to provide consistent functionality across years of use, unit tests are one of the few reliable and scalable ways to ensure the code continues to function across time and platforms.

Unit tests facilitate and provide:

  • Confidence when changing a component that the end behavior is consistent or changes are detected and addressed appropriately.
  • A wide variety of code examples for using our classes and functions.
  • Confidence that the code continues to function across third party library, system library, or system image upgrades.

Our Frameworks

We have several types of unit tests, each with their own mechanisms.

  • Project-level C++ unit tests
  • System-level C++ unit tests
  • Project-level python unit tests
  • System-level python unit tests
  • (more?)

Details on how to run, write, and build each are as follows.

Project-level C++ unit tests

Please see

for the basic tutorial. For a step-by-step narration, please see

System-level C++ unit tests

This method of unit testing is deprecated. Please migrate any tests you have in indra/test/ using the project-level C++ test method. If you can't do that, consider making the test into an integration test.

We have a set of tests located in indra/test which are built and run automatically as the tests_ok target in the cmake build. The test framework is currently only set up to test the library functionality. We use the TUT Framework since it requires no runtime library, and was incredibly simple to integrate. There are special linden enhancements to the tut framework available in indra/test/lltut.h.

Project-level python unit tests

Documentation forthcoming.

System-level python unit tests

These are started by indra/test/test.py.

When to write unit tests

Write tests under any or all of these conditions:

  • After writing your functionality declaration but before implementation. At this point, all tests will fail, and you know you are done when all tests pass.
  • After you believe a class or library is complete. This is a good time to explore the edge cases.
  • When a bug has been reported, and you need to make the smallest possible piece of code which exposes the bug.

Thanks for testing!

Need to change the framework?

There's a testplan and code to help you test your changes at How to test unit test infrastructure changes.

Useful Links