Skip to content

How to write Tests

Jonas Wanke edited this page Jul 29, 2020 · 14 revisions

Creating Mock Objects for MDPixelBasedTestCase Tests

Adding a new mock object

For storing a mock object of a specific MDWidget we created a method that helps you deal with that. Have a look at the following code snippet:

aMDWidget := MDTextButton new.
MDTextButtonTest renderOnFormString: aMDWidget andStoreWithName: 'enabled_example'

So you basically just create the Widget and pass it to the Storing-Method. It will then create a method on class-side of the MDPixelBasedTestCase's subclass you specified in the category mock-objects which contains the stringified Form the MDWidget was rendered on.

Remember to set the attributes you want to write the test method for before calling the storing method.

You also should add a short comment at the top of the created mock-object method to help others understand what kind of mock object is returned and which attributes were set

Do not forget to specify the test in MDTextButtonTest tests. You may simply add at: #enabled put: true;.

Updating mock objects

For an existing mock object you may just call MDTextButtonTest updateEnabledMockObject instead of following the steps above.

But handle this method as well as updateAllMockObjects with care!

Make sure you know why the test execution fails before updating the mock objects.