1

I have a class XYZ which has some function whivh I need to test using Catch Unit-testing. I am in a state of confusion what can be the possibility to test the function. Can anyone help on this?

Test code is below:

UaStatus XYZ::encodeVariantAsBinary(UaVariant variant, UaByteString *dst)
    {
        UaStatus status;
        status = m_encoder.create();
    if (status.isGood())
    {
        status = m_encoder.writeVariant("value", variant);
        if (status.isGood())
        {
            status = m_encoder.getBuffer(*dst);
        }
    }

    return status;
}

Br/RG

  • What are you confused about? The function has an input, an output and a return value. Supply inputs and then make sure the outputs and return value are what you expect. – Anon Mail Apr 11 '17 at 14:05
  • Write out the **requirements** for the function, and then write code to test whether the requirements are satisfied. – Pete Becker Apr 11 '17 at 15:34
  • Does this function depend on the internal state of m_encoder? If so, then look up "dependency injection." Otherwise, what's the problem? Do you just not have enough test cases to cover all the different types of variants? Should you actually be testing all those cases in a test for the encoder, so you don't have to test all those here? – Kenny Ostrom Apr 11 '17 at 16:14

0 Answers0