Skip to content

Best way to reuse mocks across several tests? #389

Answered by MikeSchulze
paintedsky asked this question in FAQ
Discussion options

You must be logged in to vote

Hello @paintedsky

You should first read how a test-suite is organized => TestSuite
What you need is a so called setup hook for a test suite.

There are two of them, before and before_test.

For example, to create a mock that applies to all tests, you should use before, since these objects exist over the lifetime of an testsuite.
On the other hand, before_test, as the name suggests, is always called before each test and is thus freshly created and only available for the lifetime of a test case.

It is important when you create a mock in before to reset it for each test to reset the reset the mock counted interactions.
Typically it looks like this.

class_name MyTest
extends GdUnitTestSuite


c…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@paintedsky
Comment options

Answer selected by paintedsky
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
FAQ
Labels
question Further information is requested clarified
2 participants
Converted from issue

This discussion was converted from issue #388 on July 26, 2023 19:37.