# Whats the proper way to write unit tests using IMPLEMENT\_SIMPLE\_AUTOMATION\_TEST?

**URL:** <https://forums.unrealengine.com/t/whats-the-proper-way-to-write-unit-tests-using-implement-simple-automation-test/768244>\
**Category:** C++\
**Tags:** automated-testing, unreal-engine, test, question\
**Created:** [February 10, 2023, 7:20pm UTC](https://forums.unrealengine.com/t/whats-the-proper-way-to-write-unit-tests-using-implement-simple-automation-test/768244 "2023-02-10T19:20:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![edugomez102](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@edugomez102](https://forums.unrealengine.com/u/edugomez102)\
**Post date:** [February 10, 2023, 7:20pm UTC](https://forums.unrealengine.com/t/whats-the-proper-way-to-write-unit-tests-using-implement-simple-automation-test/768244/1 "2023-02-10T19:20:45Z")

</div>

I’ve read some articles that suggest you to write _one_ unit test per methdo to evaluate on your class.  
Using `IMPLEMENT_SIMPLE_AUTOMATION_TEST` that would be something similar to:

```cpp

IMPLEMENT_SIMPLE_AUTOMATION_TEST(FExampleFeature01,
	"Example.feature01", EAutomationTestFlags::EditorContext | EAutomationTestFlags::ProductFilter)

bool FExampleFeature01::RunTest(const FString& Parameters)
{
	// Implement test
	TestEqual(TEXT("Checking feature 01"), ...);
	return true;
}

IMPLEMENT_SIMPLE_AUTOMATION_TEST(FExampleFeature02,
	"Example.feature02", EAutomationTestFlags::EditorContext | EAutomationTestFlags::ProductFilter)

bool FExampleFeature02::RunTest(const FString& Parameters)
{
	// Implement test
	TestEqual(TEXT("Checking feature 02"), ...);
	return true;
}

...

```

But in the Engine’s code there are some tests that are written in a way that `IMPLEMENT_SIMPLE_AUTOMATION_TEST` is used to test various methods of a class.

For example in [StringViewTest.cpp](https://github.com/EpicGames/UnrealEngine/blob/release/Engine/Source/Runtime/Core/Private/Tests/Containers/StringViewTest.cpp)

```cpp
IMPLEMENT_SIMPLE_AUTOMATION_TEST(FStringViewTestCtor, TEST_NAME_ROOT ".Ctor", TestFlags)
bool FStringViewTestCtor::RunTest(const FString& Parameters)
{
	// Default View
	{
		FStringView View;
		TestEqual(TEXT(""), View.Len(), 0);
		TestTrue(TEXT("View.IsEmpty"), View.IsEmpty());
	}

	// Empty View
	{
		FStringView View(TEXT(""));
		TestEqual(TEXT(""), View.Len(), 0);
		TestTrue(TEXT("View.IsEmpty"), View.IsEmpty());
	}

	// Constructing from nullptr is supported; nullptr interpreted as empty string
	{
		FStringView View(nullptr);
		TestEqual(TEXT(""), View.Len(), 0);
		TestTrue(TEXT("View.IsEmpty"), View.IsEmpty());
	}
	// Create from a wchar literal
	{
		FStringView View(TEXT("Test Ctor"));
		TestEqual(TEXT("View length"), View.Len(), FCStringWide::Strlen(TEXT("Test Ctor")));
		TestEqual(TEXT("The result of Strncmp"), FCStringWide::Strncmp(View.GetData(), TEXT("Test Ctor"), View.Len()), 0);
		TestFalse(TEXT("View.IsEmpty"), View.IsEmpty());
	}

	// Create from a sub section of a wchar literal
	{
		FStringView View(TEXT("Test SubSection Ctor"), 4);
		TestEqual(TEXT("View length"), View.Len(), 4);
		TestEqual(TEXT("The result of Strncmp"), FCStringWide::Strncmp(View.GetData(), TEXT("Test"), View.Len()), 0);
		TestFalse(TEXT("View.IsEmpty"), View.IsEmpty());
	}

...

```

My question is, what’s the proper way to write this tests?

---

<div class="post-metadata">

**Author:** ![PresumptivePanda](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/presumptivepanda/32/1194593_2.png) [@PresumptivePanda](https://forums.unrealengine.com/u/PresumptivePanda)\
**Post date:** [February 15, 2023, 2:20am UTC](https://forums.unrealengine.com/t/whats-the-proper-way-to-write-unit-tests-using-implement-simple-automation-test/768244/2 "2023-02-15T02:20:20Z")

</div>

Hi there @edugomez102. Hope you’re well.

This topic has been moved from **International** to **Programming & Scripting: C++**.

When posting, please review the categories to ensure your topic is posted in the most relevant space.

Thanks and happy developing! 🙂
