I ended up using a combination of Rene's and lisu's answers to solve the problem of non-default constructors:
class ToBeTested
{
public:
ToBeTested() = delete;
ToBeTested(int p): p1(p) {}
protected:
bool SensitiveInternal(int p2) {return p1 == p2;}// Still needs testing
const int p1;
};
// Stub to bridge the acess restrictions:
class ToBeTestedStub : public ToBeTested
{
public:
ToBeTestedStub(int p):ToBeTested(p) {}
FRIEND_TEST(ToBeTestedFixture, TestSensitive);
};
// Google-test:
class ToBeTestedFixture : public testing::Test
{
public:
void SetUp() override
{
stub = std::make_unique<ToBeTestedStub>(1);
}
// Using a pointer so we can instantiate the stub in the SetUp method.
std::unique_ptr<ToBeTestedStub> stub;
};
TEST_F(ToBeTestedFixture, TestSensitive)
{
ASSERT_TRUE(stub->SensitiveInternal(1));
ASSERT_FALSE(stub->SensitiveInternal(2));
}
An alternative is shown in this answer:
// Stub to bridge the acess restrictions:
class ToBeTestedStub : public ToBeTested
{
public:
ToBeTestedStub(int p):ToBeTested(p) {}
using ToBeTested::SensitiveInternal;
};