06/05/2021
自动化系统
别名自动测试(AutoTest),由UE4提供的。首先看一下UE4的例子。打开Window->DeveloperTool->SessionFrontend->Automation。
可以选择System->Engine->FileSystem 和Attachment选项,然后开始测试
创建自动的自动化
此系统存在于"UObject"生态系统之外,所以它对 蓝图 或引擎的 反射系统 不可见
简单测试
创建一个空的[Name]Test.cpp文件
//UE4官方例子
#include "Misc/AutomationTest.h"
IMPLEMENT_SIMPLE_AUTOMATION_TEST(FPlaceholderTest, "TestGroup.TestSubgroup.Placeholder Test", EAutomationTestFlags::EditorContext | EAutomationTestFlags::EngineFilter)
bool FPlaceholderTest::RunTest(const FString& Parameters)
{
// 通过返回"真(true)"使测试通过,或者返回"假(false)"使测试失败。
return true;
}
打开Session Frontend可以看到测试函数,因为EAutomationTestFlags::EditorContext
//在Console command 也可以运行自动化,按照下面写法
automation runtest TestGroup.TestSubgroup.Placeholder Test
下面列子存在Runtime\Engine\Private\Tests\EngineAutomationTests.cpp,和官网提供的一致
IMPLEMENT_SIMPLE_AUTOMATION_TEST(FSetResTest, "System.Windows.Set Resolution", EAutomationTestFlags::ClientContext | EAutomationTestFlags::EngineFilter)
bool FSetResTest::RunTest(const FString& Parameters)
{
//Gets the default map that the game uses.
const UGameMapsSettings* GameMapsSettings = GetDefault<UGameMapsSettings>();
const FString& MapName = GameMapsSettings->GetGameDefaultMap();
//Opens the actual default map in game.
GEngine->Exec(GetSimpleEngineAutomationTestGameWorld(GetTestFlags()), *FString::Printf(TEXT</