chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
0 votes

Hello everyone,

I just started with writing a test using Isolator++. I installed it like described in the documentation and tried to write a test. Unfortunately it didn't work so I tried the example from the document of DoInstead:

class Person

{

private:

   static int groupID;

public:

   int GetAge() { return 0; }

   static int GetAverageAge() { return 0; } 

   static bool IsPartOfGroup(int newGroupID) { return false; }

};

 class AltPerson

{

public:

   int ReturnAnotherAge() { return 10; }

   static int ReturnAnotherAverageAge() { return 20; } 

};

TEST_F(Examples, DoInsteadForInstanceMethod)

{

   Person* livePerson = new Person();        

   AltPerson* altPerson = new AltPerson();

     WHEN_CALLED(livePerson->GetAge()).DoMemberFunctionInstead(altPerson,ReturnAnotherAge);

    ASSERT_EQ(10, livePerson->GetAge());

    ISOLATOR_CLEANUP();

}

I get the same error message than with my own classes:

The function 'AltPerson::ReturnAnotherAge' could not be found. If the method is not called in the code under test it will be optimized away. Remove any inline keywords, and Add ISOLATOR_TESTABLE to the method.

What might be the problem? What am I doing wrong?

Is ISOLATOR_TESTABLE neccessary in each method?

I use it with google test and have installed the newest version. Do you need any further information?

Thanks a lot in advance,

Michaela

closed with the note: User recieved an answer on his question, using ISOLATOR_TESTABLE so compiler won't optimize (remove) the method.
asked by MB (1.6k points)
closed by Alon_TypeMock

1 Answer

0 votes
 
Best answer

Hi Michaela,

Thank you for the information.
We were able to reproduce the issue in our machines.
It seems that it has something to do with our integration with Google Test.
Running the same code with MsTest framework is working.

Also, adding ISOALTOR_TESTABLE macro to the AltPerson class is working.

Of course we are working on fixing it.
Is adding ISOALTOR_TESTABLE macro to the class a good workaround for you?

Cheers,
Alon Sapozhnikov.
Support Specialist.

answered by Alon_TypeMock (9k points)
selected by MB
Hello Alon,

yes, this is a workaround I can work with. Thanks for having a look at it and for fixing it.

Greetings,

Michaela

Hi Michaela,

I misleaded you before.
This has nothing to do with the testing framework.
The compiler is removing unused methods in runtime.
And because there is no actual call to the method, it's being removed.

So the soltuion is using the ISOALTOR_TESTABLE attribute.

Cheers,
Alon Sapozhnikov.
Support Specialist.

...