# How to design a test object

# Why would you want to design a test object?

Test objects help you to know if you configured your project correctly.

You might already use real documents from your production data, but they rarely cover everything you want to test for. Extreme or rare occurrences are hard to find in your data, or not even in there at all yet, if you try to build a project future-proof.

To cover those bases, one or more specifically designed test objects can help a lot. The results of working with test objects can be notably improved if you design them following certain principles.

This article describes how to design a test object like that.

# What is a test object

A test object is a Document that is usable in the Composer as a basis for the previews. Every element in the Write and Transform tabs will render a preview of its evaluations for that test object.

Test objects can either be selected from your uploaded Documents or you can design one for testing something specific. The latter can be helpful if you want to check for rare behavior, want to cover fringe combinations of data, need to quickly mock up a test case or simply want a small test data set without irrelevant overhead.

TIP

For the types of errors you can prevent or trace with a test object, see our article on how debugging works (opens new window).

# What do you want to know?

Make sure you know the purpose of a test object.

Analyse what you want to test first. Do you want to ...

  • test for a correct trigger?
  • test for a correct replace?
  • test for a correct calculation?
  • test for a correct sorting of a list of stuff?

Ask yourself the question of your desired result first. If it is more complex, don't be afraid to write it down somewhere. A good picture of what you want to achieve is key.

# How can you test it?

Find out how you would test the desired behavior.

If you need to test cases that you know are in your production data, pick some common cases from your data set that you need to work. Next, find out if there are rare cases or outliers in your data set that you also want to work and pick them all.

If you are preparing your project for cases you anticipate to encounter in the future, start by writing down some cases that you would like to work.

Pick or design test cases for all your desired outcomes. If you are testing a trigger, for example, create a test object that should make it true and another that should make it false. If you are testing the replacement of a word, test for the exact word, a longer version, a shorter version and something completely different.

These are the cases that you need to design test objects for. Depending on the nature of the data and test cases, each of these cases may become a separate test object.

# Stay close to your production data

The configuration in your project is built very specifically for the structure and content of your data. Stick to them in test objects also!

Build test objects that have the same data structure as your production data, so that you can test your project's configuration without modifying data paths, data types or filters in your project.

In the same manner, write your test object's data values the same way as they are found in your production data. A deviation in that regard may result in wrong test results, an expression or rule may do what you want in the test object but fail for production data.

# Simplicity is key!

Custom test objects are routinely built to check for very specific circumstances. Build your test object for a specific purpose only and don't be afraid to make a new one to test something else.

# Verify your test data

Be vigilant to check your test data if it is consistent.

An error that is made in a test object will result in a wrong configuration in the project.

# Put the test objects to use

After you designed or picked an appropriate number of test objects, start implementing the desired configuration in your project.

Now test with your test objects and observe if the behavior is as expected. If so, great! If not, locate the mistake and check again.

Repeat this cycle until all of your selected test objects produce adequate results.