Test Structure

Top  Previous  Next

Isolator++ Professional follows the AAA (Arrange-Act-Assert) pattern for unit tests, which helps maintain a clear and consistent test structure. This pattern involves three main steps:

 

1. Arrange: Set up the test environment, including creating any fake objects and preparing the code under test.

2. Act: Invoke the code under test.

3. Assert: Verify that the expected interactions occurred, such as confirming that a method on a fake object was called.

 

By following this structure consistently, your tests become easier to understand for both new developers and casual readers.

 

 

Setting Up a Basic Test:

 

Start by including the Isolator5 header file to access Isolator++ functionality:

 

#include "Isolator5.h"
using namespace Typemock;

 

Every test should create an Isolator object to ensure that fake objects are cleared after the test is completed. If you wish to reuse the same fakes across multiple tests, consider creating the Isolator object in the test setup and deleting it in the teardown.

 

Example: GTest

 

TEST_F(MyFirstTestSuite, FakeATurtle)

{

   // Arrange

   auto a = Isolator();  // create in test

   auto t = a.Fake.Instance<Turtle>()

 

// Isolator is out of scope and all Fakes are cleared

 

 

Using Fixture-Wide Fakes in Unit Test Setup and Teardown

 

If you want to use the same fakes across multiple tests, you can create the Isolator object in the setup method and delete it in the teardown method. This can be done by setting up test fixtures.

 

Example: GTest

 

class MyTests: public ::testing::Test

{

public:

      Isolator* a;

 virtual void SetUp() 

 {

         a = new Isolator();

         // Arrange fixture wide fakes...

 }

 virtual void TearDown() 

 {

         delete a;

 }

};

 

 

Example: MSTest

 

TEST_CLASS(Conditional)

{

public:

     Isolator* a;

 TEST_METHOD_INITIALIZE(SetUp)

 {

         a = new Isolator();

         // Arrange fixture wide fakes...

 }

 

 TEST_METHOD_CLEANUP(TearDown)

 {

         delete a;

 }

};

 

 

Additional Resources:

To see what dll's need to be copied to the output see Files required in output directory

To see how the under test project must be defined see Requirements for projects under test


Copyright  Typemock Ltd. 2009-2025.  All Rights Reserved.