Mar*_*sos 3 c++ testing catch-unit-test bazel catch2
我已经启动了一个简单的 C++ 项目,该项目使用 Bazel 作为构建系统,并希望将 Catch2 添加到其中作为测试框架。
这是我的项目到目前为止的样子:
WORKSPACE -> empty file
src/
Money.hpp
Money.cpp
BUILD
Run Code Online (Sandbox Code Playgroud)
其中 BUILD 只是
WORKSPACE -> empty file
src/
Money.hpp
Money.cpp
BUILD
Run Code Online (Sandbox Code Playgroud)
我希望能够为每个创建测试cc_library,在本例中为Money. 我尝试设置它,但与 Catch2 main 感到困惑。任何有关如何做到最好的建议都将受到赞赏!
Bazel 开箱即用地支持 Catch2 (v2.13.0)。
例子
工作空间.bazel:
workspace(name = "Catch2Demo")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "catch2",
strip_prefix = "Catch2-2.13.0",
urls = ["https://github.com/catchorg/Catch2/archive/v2.13.0.tar.gz"],
)
Run Code Online (Sandbox Code Playgroud)
构建.bazel:
cc_test(
name = "my_test",
srcs = ["my_test.cpp"],
defines = ["CATCH_CONFIG_MAIN"],
deps = [
"@catch2",
],
)
Run Code Online (Sandbox Code Playgroud)
my_test.cpp:
#include <catch2/catch.hpp>
unsigned int Factorial( unsigned int number ) {
return number <= 1 ? number : Factorial(number-1)*number;
}
TEST_CASE( "Factorials are computed", "[factorial]" ) {
REQUIRE( Factorial(1) == 1 );
REQUIRE( Factorial(2) == 2 );
REQUIRE( Factorial(3) == 6 );
REQUIRE( Factorial(10) == 3628800 );
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1512 次 |
| 最近记录: |