Skip to content

Latest commit

 

History

History
320 lines (221 loc) · 8.37 KB

File metadata and controls

320 lines (221 loc) · 8.37 KB

🧠 Typemock Isolator++ FAQ (C and C++) — Complete v5 Edition

This FAQ includes setup, runtime issues, faking examples, and advanced topics like threading, linking, and CI/CD deployment.


🔧 Common Errors & Setup

Why don’t my fakes apply at runtime?

Checks to make first:

  • Headers & libs: include the v5 headers and link the Isolator++ runtime (e.g., isolator5.h and isolator.dll / isolator.so).
  • Symbols: build your tests with debug symbols so hooks can resolve (GCC/Clang: -g, MSVC: /Zi + PDBs).
  • Toolchain: use a supported compiler (GCC ≥ 5.4, Clang ≥ 10, MSVC 2015+), with C++11+.
  • Runtime search paths: ensure the dynamic library is discoverable (LD_LIBRARY_PATH).
  • Optimizations: very aggressive LTO/IPO can inline/remove targets; reduce these for test builds.

📘 Setup Guide →


What does “Isolator++ is a runtime library” mean?

You link the Typemock runtime into your test binary; there is no separate “mocking exe”.
At runtime, Isolator++ intercepts function/method calls and applies your configured behaviors.

📘 Getting Started →


🧱 v5 Mocking Techniques (Fluent)

How do I fake a global/free function?
#include "isolator5.h"

int GlobalFunc();

TEST(Fakes, GlobalFunction_v5)
{
    auto a = Isolator();
    a.CallTo(::GlobalFunc).WillReturn(42);

    EXPECT_EQ(42, GlobalFunc());
}

📘 Fake Global Functions →


How do I fake a static method?
auto a = Isolator();
a.CallTo(UserStore::Connect).WillReturn(true);

📘 Fake Static methods →


How do I fake a member method for all instances vs a specific instance?
auto a = Isolator();

// All instances
auto futureHandle = a.Fake.All<Calculator>();
a.CallTo(futureHandle.Add(A::Any())).WillReturn(99);

// Specific object
Calculator c;
a.CallTo(c.Add(A::Any())).WillReturn(7);

📘 Faking Member Methods →


How do I control future constructor calls (objects created later)?
auto a = Isolator();
auto handle = a.Fake.All<Calculator>();
a.CallTo(handle.Add()).WillReturn(5);
RunProductionCode();

📘 Faking Future Instances →


How do I limit fakes to a scope (During filters)?

This is an Enterprise feature.

auto a = Isolator();
a.CallTo(::LookupUser()).During(
  A::Call(DoExpensiveOperation)
).WillReturn("eli");

📘 During Filters →


⚙️ Integration & Frameworks

Which C++ test frameworks can I use?

Google Test, Catch2, Boost.Test, CppUnit, and MSTest for C++ are supported.

📘 Framework Compatibility →


How do I add Isolator++ to my build?
find_library(ISOLATOR_LIB isolator REQUIRED PATHS /opt/typemock/lib)
include_directories(/opt/typemock/include)

add_executable(mytests tests.cpp)
target_link_libraries(mytests PRIVATE ${ISOLATOR_LIB} pthread)

📘 Setup Windows → 📘 Setup Linux →


🐧 Linux / Toolchain Notes

Any special flags for Linux or Clang/GCC?
  • Build with -g for symbols.
  • Disable LTO/IPO for test builds.
  • Use -fPIC for shared libs.

⚡ Performance & Coverage

Will faking slow my suite?

Overhead is low.
Fake only what you need. Disable logs and verbose/


Can I use coverage tools with Isolator++?

Yes — works with gcov, lcov, llvm-cov, and Windows coverage tools.

📘 Code Coverage →


☁️ CI/CD & Licensing

How do I run on CI and build agents?

Enterprise feature — configure license via:

IsolatorConfigurator [key] [license]

or include in header.

📘 Enterprise License →


🧩 Advanced Scenarios

How do I stub I/O, sockets, or file system access?
auto a = Isolator();
a.CallTo(::ReadFile).WillReturn(std::string{"mock-data"});

How do I verify that a behavior occurred?

Use your test framework assertions or fake spies to verify calls.

auto a = Isolator();
auto fake = a.Fake.Instance<Calculator>();
// use fake...

// verify 
a.CallTo(fake.Add(A::Eq(1))).VerifyWasCalled();

📘 Verifying Calls →


🧰 Additional Troubleshooting Topics

Linking & Runtime Loading

Link isolator.lib or libisolator.so correctly.
Add library path using -L or Linker → Additional Library Directories.

📘 Build and Link Guide →


Object Lifetime and Destructors

Keep the Isolator() object alive while tests run. Avoid faking destructors directly.


Virtual vs Non-Virtual Methods

Fakes apply to both; non-virtual fakes don’t require refactoring.

📘 Faking Non-Virtual →


Templates and Inline Functions

Ensure instantiations are visible; disable LTO for inline symbols.


Thread Safety

Typemock Isolator++ is Thread-safe and fakes can be fakes across threads. to limit a fake to a single thead use

During(A::Thread(GetCurrentThreadId())));

📘 During Thread Safety →


Exceptions

a.CallTo(&Service::Connect).WillThrow(std::runtime_error("fail"));

📘 Faking with Exceptions →


Mocking C Functions

int LegacyFunc(const char*);
auto a = Isolator();
a.CallTo(::LegacyFunc()).WillReturn(0);

📘 Mocking C Functions →


Architecture Compatibility

Use correct runtime for 32/64-bit; don’t mix. the 32bit libs are in /bin directory under the installation and the 64bit libs are in the /bin/64 diretory


Debugging Crashes or Unresolved Fakes

use Configuration.exe --log_enable or on windows run the Configurator

for During use

IsolatorConfig::VerboseLogging

📘 Troubleshooting →


🧭 Summary

Typemock Isolator++ v5 enables you to:

  • ✅ Mock any function, static, or method (virtual or not)
  • ✅ Scope and verify calls with clean syntax
  • ✅ Test legacy code on Windows and Linux
  • ✅ Integrate into CI/CD securely
  • ✅ Use AI-based suggestions via LLM API

📚 Helpful Links