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
 
struct  kafka::utest::Message
 Message owning data wrapper for unit tests. More...
 
class  kafka::utest::KafkaCluster
 Helper for Kafka unit testing. More...
 

Macros

#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.
 
#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.
 

Macro Definition Documentation

◆ EXPECT_UINVARIANT_FAILURE

#define EXPECT_UINVARIANT_FAILURE ( statement)

Test that a UINVARIANT check triggers

Definition at line 142 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 237 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 212 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 227 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 172 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 179 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 186 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 193 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 200 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 252 of file utest.hpp.

◆ UASSERT_NO_THROW

#define UASSERT_NO_THROW ( statement)

An equivalent to EXPECT_THROW with better diagnostics

Definition at line 123 of file assert_macros.hpp.

◆ UASSERT_THROW

#define UASSERT_THROW ( statement,
exception_type )

An equivalent to ASSERT_THROW with better diagnostics

Definition at line 106 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 88 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 115 of file assert_macros.hpp.

◆ UEXPECT_THROW

#define UEXPECT_THROW ( statement,
exception_type )

An equivalent to EXPECT_THROW with better diagnostics

Definition at line 97 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 78 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.

Examples
samples/hello_service/unittests/say_hello_test.cpp, and samples/s3api/unittests/client_test.cpp.

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 125 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.

Examples
samples/kafka_service/unittest/kafka_test.cpp.

Definition at line 139 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 145 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 152 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 132 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 159 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 165 of file utest.hpp.