userver: Unit-testing (utest)
Loading...
Searching...
No Matches
Unit-testing (utest)

Detailed Description

Versions of gtest macros that run tests in a coroutine environment and other helpers.

There are the following extensions:

  1. _MT ("multi-threaded") macro versions take 'thread_count' integer as the 3rd parameter at the test definition. It specifies the number of worker threads that should be created for the test. By default, there is only 1 worker thread, which should be enough for most tests;
  2. GetThreadCount() method is available in the test scope.

Usage examples:

UTEST(Semaphore, PassAcrossCoroutines) {
std::shared_lock guard{s};
auto task = utils::Async("test", [guard = std::move(guard)] {});
task.WaitFor(utest::kMaxTestWaitTime);
EXPECT_TRUE(task.IsFinished());
}
UTEST_MT(SemaphoreLock, LockMoveCopyOwning, 2) {
ASSERT_TRUE(lock.OwnsLock());
engine::SemaphoreLock move_here{std::move(lock)};
// NOLINTNEXTLINE(bugprone-use-after-move,clang-analyzer-cplusplus.Move)
EXPECT_FALSE(lock.OwnsLock());
EXPECT_TRUE(move_here.OwnsLock());
}

See Unit Tests and Benchmarks for more usage examples and descriptions

Classes

struct  utest::PrintTestName
 Test name printer for parameterized tests written in gtest. More...
 
class  utest::SimpleServer
 

Macros

#define UEXPECT_THROW_MSG(statement, exception_type, message_substring)
 
#define UASSERT_THROW_MSG(statement, exception_type, message_substring)
 
#define UEXPECT_THROW(statement, exception_type)
 
#define UASSERT_THROW(statement, exception_type)
 
#define UEXPECT_NO_THROW(statement)
 
#define UASSERT_NO_THROW(statement)
 
#define EXPECT_UINVARIANT_FAILURE(statement)
 
#define UEXPECT_DEATH(statement, message)
 An optimized equivalent of EXPECT_DEATH.
 
#define UTEST(test_suite_name, test_name)
 An equivalent of the gtest macro TEST that starts the test body as a coroutine task.
 
#define UTEST_DEATH(test_suite_name, test_name)
 An equivalent of the gtest macro TEST for death tests that starts the test body as a coroutine task.
 
#define UTEST_MT(test_suite_name, test_name, thread_count)
 An equivalent of the gtest macro TEST that starts the test body as a coroutine task.
 
#define UTEST_F(test_suite_name, test_name)
 An equivalent of the gtest macro TEST_F that starts the test body as a coroutine task.
 
#define UTEST_F_DEATH(test_suite_name, test_name)
 An equivalent of the gtest macro TEST_F for death tests that starts the test body as a coroutine task.
 
#define UTEST_F_MT(test_suite_name, test_name, thread_count)
 An equivalent of the gtest macro TEST_F that starts the test body as a coroutine task.
 
#define UTEST_P(test_suite_name, test_name)
 An equivalent of the gtest macro TEST_P that starts the test body as a coroutine task.
 
#define UTEST_P_MT(test_suite_name, test_name, thread_count)
 An equivalent of the gtest macro TEST_P that starts the test body as a coroutine task.
 
#define TYPED_UTEST(test_suite_name, test_name)
 An equivalent of the gtest macro TYPED_TEST that starts the test body as a coroutine task.
 
#define TYPED_UTEST_MT(test_suite_name, test_name, thread_count)
 An equivalent of the gtest macro TYPED_TEST that starts the test body as a coroutine task.
 
#define TYPED_UTEST_P(test_suite_name, test_name)
 An equivalent of the gtest macro TYPED_TEST_P that starts the test body as a coroutine task.
 
#define TYPED_UTEST_P_MT(test_suite_name, test_name, thread_count)
 An equivalent of the gtest macro TYPED_TEST_P that starts the test body as a coroutine task.
 
#define TYPED_UTEST_SUITE(test_suite_name, types)
 An equivalent of the gtest macro TYPED_TEST_SUITE that starts the test body as a coroutine task.
 
#define INSTANTIATE_UTEST_SUITE_P(prefix, test_suite_name, ...)
 An equivalent of the gtest macro INSTANTIATE_TEST_SUITE_P that starts the test body as a coroutine task.
 
#define REGISTER_TYPED_UTEST_SUITE_P(test_suite_name, ...)
 An equivalent of the gtest macro REGISTER_TYPED_TEST_SUITE_P that starts the test body as a coroutine task.
 
#define INSTANTIATE_TYPED_UTEST_SUITE_P(prefix, test_suite_name, types)
 An equivalent of the gtest macro INSTANTIATE_TYPED_TEST_SUITE_P that starts the test body as a coroutine task.
 
#define TYPED_UTEST_SUITE_P(test_suite_name)
 An equivalent of the gtest macro TYPED_TEST_SUITE_P that starts the test body as a coroutine task.
 

Macro Definition Documentation

◆ EXPECT_UINVARIANT_FAILURE

#define EXPECT_UINVARIANT_FAILURE ( statement)

Test that a UINVARIANT check triggers

Definition at line 120 of file assert_macros.hpp.

◆ INSTANTIATE_TYPED_UTEST_SUITE_P

#define INSTANTIATE_TYPED_UTEST_SUITE_P ( prefix,
test_suite_name,
types )

An equivalent of the gtest macro INSTANTIATE_TYPED_TEST_SUITE_P that starts the test body as a coroutine task.

Definition at line 243 of file utest.hpp.

◆ INSTANTIATE_UTEST_SUITE_P

#define INSTANTIATE_UTEST_SUITE_P ( prefix,
test_suite_name,
... )

An equivalent of the gtest macro INSTANTIATE_TEST_SUITE_P that starts the test body as a coroutine task.

Definition at line 220 of file utest.hpp.

◆ REGISTER_TYPED_UTEST_SUITE_P

#define REGISTER_TYPED_UTEST_SUITE_P ( test_suite_name,
... )

An equivalent of the gtest macro REGISTER_TYPED_TEST_SUITE_P that starts the test body as a coroutine task.

Definition at line 233 of file utest.hpp.

◆ TYPED_UTEST

#define TYPED_UTEST ( test_suite_name,
test_name )

An equivalent of the gtest macro TYPED_TEST that starts the test body as a coroutine task.

Definition at line 177 of file utest.hpp.

◆ TYPED_UTEST_MT

#define TYPED_UTEST_MT ( test_suite_name,
test_name,
thread_count )

An equivalent of the gtest macro TYPED_TEST that starts the test body as a coroutine task.

Parameters
thread_countthe number of threads to process tasks

Definition at line 185 of file utest.hpp.

◆ TYPED_UTEST_P

#define TYPED_UTEST_P ( test_suite_name,
test_name )

An equivalent of the gtest macro TYPED_TEST_P that starts the test body as a coroutine task.

Definition at line 192 of file utest.hpp.

◆ TYPED_UTEST_P_MT

#define TYPED_UTEST_P_MT ( test_suite_name,
test_name,
thread_count )

An equivalent of the gtest macro TYPED_TEST_P that starts the test body as a coroutine task.

Parameters
thread_countthe number of threads to process tasks

Definition at line 200 of file utest.hpp.

◆ TYPED_UTEST_SUITE

#define TYPED_UTEST_SUITE ( test_suite_name,
types )

An equivalent of the gtest macro TYPED_TEST_SUITE that starts the test body as a coroutine task.

Definition at line 207 of file utest.hpp.

◆ TYPED_UTEST_SUITE_P

#define TYPED_UTEST_SUITE_P ( test_suite_name)

An equivalent of the gtest macro TYPED_TEST_SUITE_P that starts the test body as a coroutine task.

Definition at line 255 of file utest.hpp.

◆ UASSERT_NO_THROW

#define UASSERT_NO_THROW ( statement)

An equivalent to EXPECT_THROW with better diagnostics

Definition at line 98 of file assert_macros.hpp.

◆ UASSERT_THROW

#define UASSERT_THROW ( statement,
exception_type )

An equivalent to ASSERT_THROW with better diagnostics

Definition at line 80 of file assert_macros.hpp.

◆ UASSERT_THROW_MSG

#define UASSERT_THROW_MSG ( statement,
exception_type,
message_substring )

An equivalent to ASSERT_THROW with an additional check for a message substring

Definition at line 60 of file assert_macros.hpp.

◆ UEXPECT_DEATH

#define UEXPECT_DEATH ( statement,
message )

An optimized equivalent of EXPECT_DEATH.

Definition at line 39 of file death_tests.hpp.

◆ UEXPECT_NO_THROW

#define UEXPECT_NO_THROW ( statement)

An equivalent to EXPECT_NO_THROW with better diagnostics

Definition at line 89 of file assert_macros.hpp.

◆ UEXPECT_THROW

#define UEXPECT_THROW ( statement,
exception_type )

An equivalent to EXPECT_THROW with better diagnostics

Definition at line 70 of file assert_macros.hpp.

◆ UEXPECT_THROW_MSG

#define UEXPECT_THROW_MSG ( statement,
exception_type,
message_substring )

An equivalent to EXPECT_THROW with an additional check for a message substring

Definition at line 49 of file assert_macros.hpp.

◆ UTEST

#define UTEST ( test_suite_name,
test_name )

An equivalent of the gtest macro TEST that starts the test body as a coroutine task.

Definition at line 119 of file utest.hpp.

◆ UTEST_DEATH

#define UTEST_DEATH ( test_suite_name,
test_name )

An equivalent of the gtest macro TEST for death tests that starts the test body as a coroutine task.

Definition at line 126 of file utest.hpp.

◆ UTEST_F

#define UTEST_F ( test_suite_name,
test_name )

An equivalent of the gtest macro TEST_F that starts the test body as a coroutine task.

Definition at line 141 of file utest.hpp.

◆ UTEST_F_DEATH

#define UTEST_F_DEATH ( test_suite_name,
test_name )

An equivalent of the gtest macro TEST_F for death tests that starts the test body as a coroutine task.

Definition at line 148 of file utest.hpp.

◆ UTEST_F_MT

#define UTEST_F_MT ( test_suite_name,
test_name,
thread_count )

An equivalent of the gtest macro TEST_F that starts the test body as a coroutine task.

Parameters
thread_countthe number of threads to process tasks

Definition at line 156 of file utest.hpp.

◆ UTEST_MT

#define UTEST_MT ( test_suite_name,
test_name,
thread_count )

An equivalent of the gtest macro TEST that starts the test body as a coroutine task.

Parameters
thread_countthe number of threads to process tasks

Definition at line 134 of file utest.hpp.

◆ UTEST_P

#define UTEST_P ( test_suite_name,
test_name )

An equivalent of the gtest macro TEST_P that starts the test body as a coroutine task.

Definition at line 163 of file utest.hpp.

◆ UTEST_P_MT

#define UTEST_P_MT ( test_suite_name,
test_name,
thread_count )

An equivalent of the gtest macro TEST_P that starts the test body as a coroutine task.

Definition at line 170 of file utest.hpp.