Automation tests do not show up in editor.

Same question:

Either way I have createt test class, in separate module, called GameAttributes, and module load is set to default. Setting it PreDefault didn’t changed anything and tests still didn’t show up in front end.

Any ideas, how, to create automation tests from scratch without using macros ?



    class GameEffectsTestSuite
    {
    	UWorld* World;
    	FAutomationTestBase* Test;
    
    	AGACharacterAttributeTest* SourceActor;
    	UGAAttributeComponent* SourceComponent;
    
    	AGACharacterAttributeTest* DestActor;
    	UGAAttributeComponent* DestComponent;
    
    public:
    	GameEffectsTestSuite(UWorld* WorldIn, FAutomationTestBase* TestIn)
    		: World(WorldIn),
    		Test(TestIn)
    	{
    		SourceActor = World->SpawnActor<AGACharacterAttributeTest>();
    		SourceComponent = SourceActor->Attributes;
    		SourceComponent->DefaultAttributes = NewObject<UGAAttributesTest>(SourceActor->Attributes);
    		SourceComponent->GetAttributes<UGAAttributesTest>()->Health.SetBaseValue(100);
    		SourceComponent->GetAttributes<UGAAttributesTest>()->Energy.SetBaseValue(100);
    		SourceComponent->GetAttributes<UGAAttributesTest>()->Stamina.SetBaseValue(100);
    
    		DestActor = World->SpawnActor<AGACharacterAttributeTest>();
    		DestComponent = DestActor->Attributes;
    		DestComponent->DefaultAttributes = NewObject<UGAAttributesTest>(SourceActor->Attributes);
    		DestComponent->GetAttributes<UGAAttributesTest>()->Health.SetBaseValue(100);
    		DestComponent->GetAttributes<UGAAttributesTest>()->Energy.SetBaseValue(100);
    		DestComponent->GetAttributes<UGAAttributesTest>()->Stamina.SetBaseValue(100);
    	}
    
    	~GameEffectsTestSuite()
    	{
    		// run after each test
    
    		// destroy the actors
    		if (SourceActor)
    		{
    			World->EditorDestroyActor(SourceActor, false);
    		}
    		if (DestActor)
    		{
    			World->EditorDestroyActor(DestActor, false);
    		}
    	}
    	void TestEqual(const FString& TestText, float Actual, float Expected)
    	{
    		Test->TestEqual(FString::Printf(TEXT("%s: %f (actual) != %f (expected)"), *TestText, Actual, Expected), Actual, Expected);
    	}
    
    	void Test_SetBaseValue()
    	{
    		float value = SourceComponent->GetAttributes<UGAAttributesTest>()->Health.GetFinalValue();
    		TestEqual(TEXT("Attribute Base Value"), value, 100);
    	}
    
    };
    class FGAAttributesTests : public FAutomationTestBase
    {
    public:
    	typedef void (GameEffectsTestSuite::*TestFunc)();
    	TArray<TestFunc> TestFunctions;
    	TArray<FString> TestFunctionNames;
    
    	FGAAttributesTests(const FString& InName)
    		: FAutomationTestBase(InName, false)
    	{
    		ADD_TEST(Test_SetBaseValue);
    	};
    	virtual uint32 GetTestFlags() const override { return EAutomationTestFlags::EditorContext | EAutomationTestFlags::SmokeFilter; }
    	virtual bool IsStressTest() const { return false; }
    	virtual uint32 GetRequiredDeviceNum() const override { return 1; }
    
    	virtual FString GetBeautifiedTestName() const override { return "System.GameAttributes.Attributes"; }
    	virtual void GetTests(TArray<FString>& OutBeautifiedNames, TArray <FString>& OutTestCommands) const override
    	{
    		for (const FString& TestName : TestFunctionNames)
    		{
    			OutBeautifiedNames.Add(TestName);
    			OutTestCommands.Add(TestName);
    		}
    	}
    	bool RunTest(const FString& Parameters)
    	{
    		TestFunc TestFunction = nullptr;
    		for (int32 i = 0; i < TestFunctionNames.Num(); ++i)
    		{
    			if (TestFunctionNames* == Parameters)
    			{
    				TestFunction = TestFunctions*;
    				break;
    			}
    		}
    		if (TestFunction == nullptr)
    		{
    			return false;
    		}
    		UWorld *World = UWorld::CreateWorld(EWorldType::Game, false);
    		FWorldContext &WorldContext = GEngine->CreateNewWorldContext(EWorldType::Game);
    		WorldContext.SetCurrentWorld(World);
    
    		FURL URL;
    		World->InitializeActorsForPlay(URL);
    		World->BeginPlay();
    
    		// run the matching test
    		uint64 InitialFrameCounter = GFrameCounter;
    		{
    			GameEffectsTestSuite Tester(World, this);
    			(Tester.*TestFunction)();
    		}
    		GFrameCounter = InitialFrameCounter;
    
    		GEngine->DestroyWorldContext(World);
    		World->DestroyWorld(false);
    		return true;
    	}
    };



For anyone interested, you need to add:



namespace
{
	FYourClassTest FYourClassTestAutomationTestInstance(TEXT("FYourClassTest"));
}

and Poof! It will work.