Coroutine support for asynchronous tests

Open
#3,077 2 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

@GaurRitika is already working on this.

Since Nov 16, 2026.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
cpp
Domain
testing-qa

Research direction

Start by reviewing Catch2's test registration and execution flow, then examine how a C++20 coroutine task could integrate with user-provided scheduling and event loops. Done means coroutine-defined tests work behind a C++20/coroutine build flag while existing C++14 support remains unaffected.

Written by the indexing model from the issue text.

Description

Description

C++20 coroutines are increasingly used for asynchronous APIs, but writing tests for coroutine-based code typically requires blocking adapters (e.g. sync_wait) or custom wrappers. This adds friction and does not work in event-loop-driven environments where blocking inside a test body is not possible.

It would therefore be useful if Catch2 supported test cases defined as coroutines, for example:

TEST_CASE_ASYNC("my async test")
{
    auto result = co_await async_operation();
    CHECK(result == 42);
}

Because Catch2 supports C++14, this feature would only be available when compiling with C++20/coroutine support. It would have to be guarded behind a build config flag.

Additional context

We have implemented a proof of concept in a private fork where we added a very basic coroutine task type. All scheduling and event-loop integration happen in user code, which keeps the approach flexible while adding minimal complexity inside Catch2. This was enough to solve related issues such as #1755 (we also target Emscripten).

I've looked at other C++ testing frameworks, but none currently seem to support coroutines natively. However, popular frameworks in other languages (e.g. C#, Python, JavaScript) support async tests, so the concept itself isn't novel.

Dominant language
C++
Stars
21.6k
Forks
3.4k
Avg merge
3d 12h
Merged PRs (30d)
5

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from catchorg/Catch2

All issues in catchorg/Catch2

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.