Howto mix TDD and RAII

Posted by f4 on Stack Overflow See other posts from Stack Overflow or by f4
Published on 2010-06-15T20:24:39Z Indexed on 2010/06/15 20:32 UTC
Read the original article Hit count: 235

Filed under:
|
|
|

I'm trying to make extensive tests for my new project but I have a problem.

Basically I want to test MyClass. MyClass makes use of several other class which I don't need/want to do their job for the purpose of the test. So I created mocks (I use gtest and gmock for testing)

But MyClass instantiate everything it needs in it's constructor and release it in the destructor. That's RAII I think.

So I thought, I should create some kind of factory, which creates everything and gives it to MyClass's constructor. That factory could have it's fake for testing purposes. But's thats no longer RAII right?

Then what's the good solution here?

© Stack Overflow or respective owner

Related posts about c++

Related posts about best-practices