Difference between revisions of "Unit tests"

From Second Life Wiki
Jump to navigation Jump to search
 
(6 intermediate revisions by the same user not shown)
Line 14: Line 14:
* Project-level C++ unit tests
* Project-level C++ unit tests
* System-level C++ unit tests
* System-level C++ unit tests
* Project-level python unit tests
* System-level python unit tests
* System-level python unit tests
* (more?)
* (more?)
Line 20: Line 21:


=== Project-level C++ unit tests ===
=== Project-level C++ unit tests ===
Please see [[How to add unit tests to indra code]]
Please see
* [[How to add unit tests to C++ code]]
 
for the basic tutorial. For a step-by-step narration, please see
* [[C++ Unit Testing - How It Works]]
* [[C++ Unit Testing - Case Study]]
* [[C++ Unit Testing - FAQ]]


=== System-level C++ unit tests ===
=== System-level C++ unit tests ===
Line 29: Line 36:
We use the [http://tut-framework.sourceforge.net/ TUT Framework] since it requires no runtime library, and was incredibly simple to integrate.
We use the [http://tut-framework.sourceforge.net/ 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.
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 ===
=== System-level python unit tests ===
Line 40: Line 50:


Thanks for testing!
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 ==
* [http://wiki.secondlife.com/wiki/Unit_tests The LL Unit Test page]
* [http://tut-framework.sourceforge.net/ The tut framework doc]
* [http://gamesfromwithin.com/?p=29 Exploring the C++ Unit Testing Framework Jungle]
* [http://www.amazon.com/Working-Effectively-Legacy-Robert-Martin/dp/0131177052/ref=sr_1_1?ie=UTF8&s=books&qid=1234193739&sr=1-1 Working Effectively with Legacy Code] by Michael Feathers: Much of that book discusses techniques for minimizing the risk of teasing apart difficult classes in order to test them.


[[Category:Automated Testing]]
[[Category:Automated Testing]]

Latest revision as of 17:04, 25 June 2009

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