Announcement

Collapse
No announcement yet.

In automated tests, how to check that an assertion is failing as expected ?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    In automated tests, how to check that an assertion is failing as expected ?

    I'm writing a C++ module to add support for ridiculously big numbers for an incremental game. I have a set of automated tests (using the new Automation Spec) to verify the behavior of arithmetic operations.

    I want to prevent anyone to accidentally divide by zero (and destroying the universe) so I'm crashing the engine if the divider is equal to zero, using a good old assertion.

    Code:
    verifyf(B.m != 0.f, TEXT("Cannot divide by 0"));
    As expected, the test below crashes the engine. The problem is that it prevents other tests to execute.

    Code:
            It("should not allow division by 0", [this]
            {
                FBigNumber A(2.f, 0);
                FBigNumber B(0.f, 0);
    
                FBigNumber result = A / B;
            });

    Is there a way to write an automated test that checks that the engine would have crashed, without actually crashing the engine?
    Co-founder and developer at Big Horn Studio

    #2
    Just wrap the verifies in a #define or some such.

    #if UE_BUILD_SHIPPING
    verifyf(B.m != 0.0f, TEXT("Cannot divide by 0"));
    #else
    Log(LogTest, Warning, TEXT("Cannot divide by 0"));
    #endif
    Able Ability System - A high performance, robust ability system for UE4. Now Available!

    Comment


      #3
      ensureMsg(expression, message);

      gives a call stack, but it shouldn't crash the engine, it keeps running.
      | Savior | USQLite | FSM | Object Pool | Sound Occlusion | Property Transfer | Magic Nodes | MORE |

      Comment

      Working...
      X