x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Using automation testing for catching expected errors

Suppose I have a piece of program that logs an error.

 void DoStuff(bool doit)
 {
     if(!doit)
     {
         UE_LOG(MyLogCategory, Error, "Cannot do stuff");
     }
 }

And I write an automation test that actually expects this log to be printed.

 IMPLEMENT_SIMPLE_AUTOMATION_TEST(DoStuffTest, "DoStuffTest.ThrowsError", EAutomationTestFlags::EngineFilter | EAutomationTestFlags::EditorContext)
 bool DoStuffTest::RunTest(const FString& Parameters)
 {
     DoStuff(false);
 
     // TODO: Assert that an error was logged and make the test pass.
 }

How can I ensure that my test passes? It now directly fails, because of the UE_LOG in the actual source code.

Product Version: UE 4.16
Tags:
more ▼

asked Jul 19 '17 at 12:29 PM in C++ Programming

avatar image

mtass
18 2 6

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Hi mtass,

We recently added support for this, and I believe it is expected to ship as part of 4.17. You'd want to use the new AddExpectedError method in the test body, which allows you to define a regex describing the expected error/warning message, the type of comparison to perform, and the number of times you expect the message to occur during the test.

Example from one of the unit tests:

 AddExpectedError(TEXT("Response \\(-?\\d+\\)"), EAutomationExpectedErrorFlags::Contains, 4);
 AddError(TEXT("Response (0)"));
 AddError(TEXT("Response (1)"));
 AddError(FString::Printf(TEXT("Response (%d)"), MIN_int64));
 AddError(FString::Printf(TEXT("Response (%d)"), MAX_uint64));

From your example, your test would look something like:

 IMPLEMENT_SIMPLE_AUTOMATION_TEST(DoStuffTest, "DoStuffTest.ThrowsError", EAutomationTestFlags::EngineFilter | EAutomationTestFlags::EditorContext)
 bool DoStuffTest::RunTest(const FString& Parameters)
 {
     AddExpectedError(TEXT("Cannot do stuff"), EAutomationExpectedErrorFlags::Exact, 1);
     DoStuff(false);
 }
more ▼

answered Jul 19 '17 at 02:09 PM

avatar image

Adr1c ♦♦ STAFF
910 18 7 18

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question