- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我在使用 Boost Unit Test Framework 实现的项目中进行了单元测试并组织成几个模块,即:
#define BOOST_TEST_MODULE Connection_test
#ifndef BOOST_TEST_DYN_LINK
#define BOOST_TEST_DYN_LINK
#endif
#ifndef BOOST_TEST_NO_MAIN
#define BOOST_TEST_NO_MAIN
#endif
#include <boost/test/unit_test.hpp>
#include <boost/test/output_test_stream.hpp>
#define BOOST_TEST_MODULE Connection_test
BOOST_AUTO_TEST_SUITE(Connection_test)
BOOST_AUTO_TEST_CASE(Connection_construction__test) {
***
}
BOOST_AUTO_TEST_SUITE_END()
我正在将每个模块编译为单个可执行文件。
我想使用 CodeCoverage.cmake模块来运行代码覆盖率分析,但我遇到了问题。我应该通过 SETUP_TARGET_FOR_COVERAGE_LCOV
指定一个测试可执行文件,但我没有只有一个。
有什么方法可以使用 CodeCoverage.cmake
一次设置多个测试可执行文件?
我已经通过 add_test()
添加了测试到我的根 CMakeLists.txt 并像这样修改了我的覆盖率目标
include(CTest)
add_test(NAME constant_neuron_test COMMAND constant_neuron_test)
add_test(NAME binary_neuron_test COMMAND binary_neuron_test)
add_test(NAME logistic_neuron_test COMMAND logistic_neuron_test)
add_test(NAME connectionFunctionGeneral_test COMMAND connectionFunctionGeneral_test)
add_test(NAME connection_Function_identity_test COMMAND connection_Function_identity_test)
add_test(NAME neural_network_test COMMAND neural_network_test)
add_test(NAME dataset_test COMMAND dataset_test)
add_test(NAME particle_swarm_test COMMAND particle_swarm_test)
add_test(NAME particle_test COMMAND particle_test)
add_test(NAME NeuralNetworkSum_test COMMAND NeuralNetworkSum_test)
add_test(NAME errorfunction_test COMMAND errorfunction_test)
add_test(NAME DESolver_test COMMAND DESolver_test)
include(CodeCoverage.cmake)
APPEND_COVERAGE_COMPILER_FLAGS()
SETUP_TARGET_FOR_COVERAGE_LCOV(
NAME coverage # New target name
EXECUTABLE ctest -C ${ROOT_DIR}/CTestTestfile.cmake # Executable in PROJECT_BINARY_DIR
DEPENDENCIES ${Boost_LIBRARIES} # Dependencies to build first
)
ctest
本身运行正确:
Test project /home/martin/4Neuro
Start 1: constant_neuron_test
1/12 Test #1: constant_neuron_test ................ Passed 0.04 sec
Start 2: binary_neuron_test
2/12 Test #2: binary_neuron_test .................. Passed 0.04 sec
Start 3: logistic_neuron_test
3/12 Test #3: logistic_neuron_test ................ Passed 0.05 sec
Start 4: connectionFunctionGeneral_test
4/12 Test #4: connectionFunctionGeneral_test ...... Passed 0.04 sec
Start 5: connection_Function_identity_test
5/12 Test #5: connection_Function_identity_test ... Passed 0.04 sec
Start 6: neural_network_test
6/12 Test #6: neural_network_test ................. Passed 0.04 sec
Start 7: dataset_test
7/12 Test #7: dataset_test ........................ Passed 0.04 sec
Start 8: particle_swarm_test
8/12 Test #8: particle_swarm_test ................. Passed 0.04 sec
Start 9: particle_test
9/12 Test #9: particle_test ....................... Passed 0.04 sec
Start 10: NeuralNetworkSum_test
10/12 Test #10: NeuralNetworkSum_test ............... Passed 0.05 sec
Start 11: errorfunction_test
11/12 Test #11: errorfunction_test .................. Passed 0.04 sec
Start 12: DESolver_test
12/12 Test #12: DESolver_test ....................... Passed 0.05 sec
100% tests passed, 0 tests failed out of 12
Total Test time (real) = 0.53 sec
但是当我尝试通过make coverage
创建我的覆盖率报告时,我得到了这个错误:
Processing code coverage counters and generating report.
cd /home/martin/4Neuro/build && /usr/bin/lcov --gcov-tool /usr/bin/gcov -directory . --zerocounters
Deleting all .da files in . and subdirectories
Done.
cd /home/martin/4Neuro/build && /usr/bin/lcov --gcov-tool /usr/bin/gcov -c -i -d . -o coverage.base
Capturing coverage data from .
Found gcov version: 7.3.0
Scanning . for .gcno files ...
geninfo: WARNING: no .gcno files found in . - skipping!
Finished .info-file creation
cd /home/martin/4Neuro/build && ctest -C /home/martin/4Neuro/CTestTestfile.cmake
Test project /home/martin/4Neuro/build
No tests were found!!!
cd /home/martin/4Neuro/build && /usr/bin/lcov --gcov-tool /usr/bin/gcov --directory . --capture --output-file coverage.info
Capturing coverage data from .
Found gcov version: 7.3.0
Scanning . for .gcda files ...
geninfo: WARNING: no .gcda files found in . - skipping!
Finished .info-file creation
cd /home/martin/4Neuro/build && /usr/bin/lcov --gcov-tool /usr/bin/gcov -a coverage.base -a coverage.info --output-file coverage.total
Combining tracefiles.
Reading tracefile coverage.base
lcov: ERROR: no valid records found in tracefile coverage.base
CMakeFiles/coverage.dir/build.make:62: recipe for target 'CMakeFiles/coverage' failed
make[3]: *** [CMakeFiles/coverage] Error 255
make[3]: Leaving directory '/home/martin/4Neuro'
CMakeFiles/Makefile2:70: recipe for target 'CMakeFiles/coverage.dir/all' failed
make[2]: *** [CMakeFiles/coverage.dir/all] Error 2
make[2]: Leaving directory '/home/martin/4Neuro'
CMakeFiles/Makefile2:77: recipe for target 'CMakeFiles/coverage.dir/rule' failed
make[1]: *** [CMakeFiles/coverage.dir/rule] Error 2
make[1]: Leaving directory '/home/martin/4Neuro'
Makefile:132: recipe for target 'coverage' failed
make: *** [coverage] Error 2
我已经像这样修改了我的 CMakeLists.txt
include(CTest)
enable_testing()
add_subdirectory(${SRC_DIR} ${PROJECT_BINARY_DIR})
# Adding Unit-tests
add_test(NAME constant_neuron_test COMMAND constant_neuron_test)
add_test(NAME binary_neuron_test COMMAND binary_neuron_test)
add_test(NAME logistic_neuron_test COMMAND logistic_neuron_test)
add_test(NAME connectionFunctionGeneral_test COMMAND connectionFunctionGeneral_test)
add_test(NAME connection_Function_identity_test COMMAND connection_Function_identity_test)
add_test(NAME neural_network_test COMMAND neural_network_test)
add_test(NAME dataset_test COMMAND dataset_test)
add_test(NAME particle_swarm_test COMMAND particle_swarm_test)
add_test(NAME particle_test COMMAND particle_test)
add_test(NAME NeuralNetworkSum_test COMMAND NeuralNetworkSum_test)
add_test(NAME errorfunction_test COMMAND errorfunction_test)
add_test(NAME DESolver_test COMMAND DESolver_test)
include(CodeCoverage.cmake)
APPEND_COVERAGE_COMPILER_FLAGS()
SETUP_TARGET_FOR_COVERAGE_LCOV(
NAME coverage # New target name
EXECUTABLE ctest -j ${n_cores} # Executable in PROJECT_BINARY_DIR
DEPENDENCIES
constant_neuron_test
binary_neuron_test
logistic_neuron_test
connectionFunctionGeneral_test
connection_Function_identity_test
neural_network_test
dataset_test
particle_swarm_test
particle_test
NeuralNetworkSum_test
errorfunction_test
DESolver_test # Dependencies to build first
)
set(COVERAGE_EXCLUDES 'external_dependencies/*')
但是,不幸的是,错误仍然存在
cd /home/martin/4Neuro/build && /usr/bin/lcov --gcov-tool /usr/bin/gcov -c -i -d . -o coverage.base
Capturing coverage data from .
Found gcov version: 7.3.0
Scanning . for .gcno files ...
geninfo: WARNING: no .gcno files found in . - skipping!
Finished .info-file creation
cd /home/martin/4Neuro/build && ctest -j 3
Test project /home/martin/4Neuro/build
No tests were found!!!
cd /home/martin/4Neuro/build && /usr/bin/lcov --gcov-tool /usr/bin/gcov --directory . --capture --output-file coverage.info
Capturing coverage data from .
Found gcov version: 7.3.0
Scanning . for .gcda files ...
geninfo: WARNING: no .gcda files found in . - skipping!
Finished .info-file creation
cd /home/martin/4Neuro/build && /usr/bin/lcov --gcov-tool /usr/bin/gcov -a coverage.base -a coverage.info --output-file coverage.total
Combining tracefiles.
Reading tracefile coverage.base
lcov: ERROR: no valid records found in tracefile coverage.base
CMakeFiles/coverage.dir/build.make:71: recipe for target 'CMakeFiles/coverage' failed
make[3]: *** [CMakeFiles/coverage] Error 255
make[3]: Leaving directory '/home/martin/4Neuro'
CMakeFiles/Makefile2:81: recipe for target 'CMakeFiles/coverage.dir/all' failed
make[2]: *** [CMakeFiles/coverage.dir/all] Error 2
make[2]: Leaving directory '/home/martin/4Neuro'
CMakeFiles/Makefile2:88: recipe for target 'CMakeFiles/coverage.dir/rule' failed
make[1]: *** [CMakeFiles/coverage.dir/rule] Error 2
make[1]: Leaving directory '/home/martin/4Neuro'
Makefile:132: recipe for target 'coverage' failed
make: *** [coverage] Error 2
最佳答案
好的,我尝试重现您的一组最小设置。
我有:
.
├── CMakeLists.txt
├── CodeCoverage.cmake
├── test1.cpp
└── test2.cpp
CodeCoverage.cmake
来自 https://github.com/bilke/cmake-modules/blob/master/CodeCoverage.cmake
CMakeLists.txt 是:
cmake_minimum_required(VERSION 3.10)
find_package(Boost COMPONENTS system filesystem unit_test_framework REQUIRED)
include(CTest)
enable_testing()
add_executable(test1_test test1.cpp)
target_link_libraries(test1_test
${Boost_FILESYSTEM_LIBRARY}
${Boost_SYSTEM_LIBRARY}
${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
add_executable(test2_test test2.cpp)
target_link_libraries(test2_test
${Boost_FILESYSTEM_LIBRARY}
${Boost_SYSTEM_LIBRARY}
${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
add_test(NAME test1_test COMMAND test1_test)
add_test(NAME test2_test COMMAND test2_test)
include(CodeCoverage.cmake)
APPEND_COVERAGE_COMPILER_FLAGS()
SETUP_TARGET_FOR_COVERAGE_LCOV(
NAME coverage
EXECUTABLE ctest -j ${n_cores} # Executable in PROJECT_BINARY_DIR
DEPENDENCIES
test1_test
test2_test)
而test1.cpp(和test2.cpp)是
#define BOOST_TEST_MODULE test1
#ifndef BOOST_TEST_DYN_LINK
#define BOOST_TEST_DYN_LINK
#endif
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>
#include <boost/test/output_test_stream.hpp>
#define BOOST_TEST_MODULE test1
BOOST_AUTO_TEST_SUITE(test1)
BOOST_AUTO_TEST_CASE(test1__test) {
BOOST_CHECK_EQUAL(1, 1);
}
BOOST_AUTO_TEST_SUITE_END()
现在我这样做了:
mkdir build
cd build
cmake ..
输出是:
-- The C compiler identification is GNU 7.3.0
-- The CXX compiler identification is GNU 7.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Boost version: 1.65.1
-- Found the following Boost libraries:
-- system
-- filesystem
-- unit_test_framework
CMake Warning at CodeCoverage.cmake:116 (message):
Code coverage results with an optimised (non-Debug) build may be misleading
Call Stack (most recent call first):
CMakeLists.txt:20 (include)
-- Appending code coverage compiler flags: -g -O0 --coverage -fprofile-arcs -ftest-coverage
-- Configuring done
-- Generating done
-- Build files have been written to: /home/jsantand/t/build
最后运行make coverage
:
Scanning dependencies of target test1_test
[ 20%] Building CXX object CMakeFiles/test1_test.dir/test1.cpp.o
[ 40%] Linking CXX executable test1_test
[ 40%] Built target test1_test
Scanning dependencies of target test2_test
[ 60%] Building CXX object CMakeFiles/test2_test.dir/test2.cpp.o
[ 80%] Linking CXX executable test2_test
[ 80%] Built target test2_test
Scanning dependencies of target coverage
[100%] Resetting code coverage counters to zero.
Processing code coverage counters and generating report.
Deleting all .da files in . and subdirectories
Done.
Capturing coverage data from .
Found gcov version: 7.3.0
Scanning . for .gcno files ...
Found 2 graph files in .
Processing test1_test.dir/test1.cpp.gcno
Processing test2_test.dir/test2.cpp.gcno
Finished .info-file creation
Test project /home/jsantand/t/build
Start 1: test1_test
1/2 Test #1: test1_test ....................... Passed 0.01 sec
Start 2: test2_test
2/2 Test #2: test2_test ....................... Passed 0.01 sec
100% tests passed, 0 tests failed out of 2
Total Test time (real) = 0.02 sec
Capturing coverage data from .
Found gcov version: 7.3.0
Scanning . for .gcda files ...
Found 2 data files in .
Processing test1_test.dir/test1.cpp.gcda
Processing test2_test.dir/test2.cpp.gcda
Finished .info-file creation
Combining tracefiles.
Reading tracefile coverage.base
Reading tracefile coverage.info
Writing data to coverage.total
Summary coverage rate:
lines......: 65.4% (229 of 350 lines)
functions..: 68.3% (110 of 161 functions)
branches...: no data found
Reading tracefile coverage.total
Deleted 0 files
Writing data to /home/jsantand/t/build/coverage.info.cleaned
Summary coverage rate:
lines......: 65.4% (229 of 350 lines)
functions..: 68.3% (110 of 161 functions)
branches...: no data found
Reading data file /home/jsantand/t/build/coverage.info.cleaned
Found 37 entries.
Found common filename prefix "/usr/include"
Writing .css and .png files.
Generating output.
Processing file /home/jsantand/t/test1.cpp
Processing file /home/jsantand/t/test2.cpp
Processing file boost/type_index.hpp
Processing file boost/function/function_base.hpp
Processing file boost/function/function_template.hpp
Processing file boost/smart_ptr/shared_ptr.hpp
Processing file boost/smart_ptr/detail/sp_counted_base_std_atomic.hpp
Processing file boost/smart_ptr/detail/shared_count.hpp
Processing file boost/test/unit_test_suite.hpp
Processing file boost/test/unit_test.hpp
Processing file boost/test/unit_test_log.hpp
Processing file boost/test/tools/assertion_result.hpp
Processing file boost/test/tools/detail/print_helper.hpp
Processing file boost/test/tools/detail/fwd.hpp
Processing file boost/test/tools/old/impl.hpp
Processing file boost/test/tree/observer.hpp
Processing file boost/test/tree/test_unit.hpp
Processing file boost/test/tree/fixture.hpp
Processing file boost/test/tree/decorator.hpp
Processing file boost/test/utils/lazy_ostream.hpp
Processing file boost/test/utils/class_properties.hpp
Processing file boost/test/utils/trivial_singleton.hpp
Processing file boost/test/utils/wrap_stringstream.hpp
Processing file boost/test/utils/basic_cstring/bcs_char_traits.hpp
Processing file boost/test/utils/basic_cstring/basic_cstring.hpp
Processing file boost/type_index/type_index_facade.hpp
Processing file boost/type_index/stl_type_index.hpp
Processing file boost/type_traits/integral_constant.hpp
Processing file c++/7/typeinfo
Processing file c++/7/bits/ios_base.h
Processing file c++/7/bits/move.h
Processing file c++/7/bits/alloc_traits.h
Processing file c++/7/bits/stl_construct.h
Processing file c++/7/bits/stl_vector.h
Processing file c++/7/bits/atomic_base.h
Processing file c++/7/bits/allocator.h
Processing file c++/7/ext/new_allocator.h
Writing directory view page.
Overall coverage rate:
lines......: 65.4% (229 of 350 lines)
functions..: 68.3% (110 of 161 functions)
Lcov code coverage info report saved in coverage.info.
Open ./coverage/index.html in your browser to view the coverage report.
[100%] Built target coverage
关于c++ - 使用具有多个目标的 CodeCoverage.cmake 进行代码覆盖率分析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52255589/
这是代码片段。 请说出这种用小内存存储大数据的算法是什么。 public static void main(String[] args) { long longValue = 21474836
所以我使用 imap 从 gmail 和 outlook 接收电子邮件。 Gmail 像这样编码 =?UTF-8?B?UmU6IM69zq3OvyDOtc68zrHOuc67IG5ldyBlbWFpb
很久以前就学会了 C 代码;想用 Scheme 尝试一些新的和不同的东西。我正在尝试制作一个接受两个参数并返回两者中较大者的过程,例如 (define (larger x y) (if (> x
Azure 恢复服务保管库有两个备份配置选项 - LRS 与 GRS 这是一个有关 Azure 恢复服务保管库的问题。 当其驻留区域发生故障时,如何处理启用异地冗余的恢复服务保管库?如果未为恢复服务启
说,我有以下实体: @Entity public class A { @Id @GeneratedValue private Long id; @Embedded private
我有下一个问题。 我有下一个标准: criteria.add(Restrictions.in("entity.otherEntity", getOtherEntitiesList())); 如果我的
如果这是任何类型的重复,我会提前申请,但我找不到任何可以解决我的具体问题的内容。 这是我的程序: import java.util.Random; public class CarnivalGame{
我目前正在使用golang创建一个聚合管道,在其中使用“$ or”运算符查询文档。 结果是一堆需要分组的未分组文档,这样我就可以进入下一阶段,找到两个数据集之间的交集。 然后将其用于在单独的集合中进行
是否可以在正则表达式中创建 OR 条件。 我正在尝试查找包含此类模式的文件名列表的匹配项 第一个案例 xxxxx-hello.file 或者案例二 xxxx-hello-unasigned.file
该程序只是在用户输入行数时创建菱形的形状,因此它有 6 个 for 循环; 3 个循环创建第一个三角形,3 个循环创建另一个三角形,通过这 2 个三角形和 6 个循环,我们得到了一个菱形,这是整个程序
我有一个像这样的查询字符串 www.google.com?Department=Education & Finance&Department=Health 我有这些 li 标签,它们的查询字符串是这样
我有一个带有静态构造函数的类,我用它来读取 app.config 值。如何使用不同的配置值对类进行单元测试。我正在考虑在不同的应用程序域中运行每个测试,这样我就可以为每个测试执行静态构造函数 - 但我
我正在寻找一个可以容纳多个键的容器,如果我为其中一个键值输入保留值(例如 0),它会被视为“或”搜索。 map, int > myContainer; myContainer.insert(make_
我正在为 Web 应用程序创建数据库,并正在寻找一些建议来对可能具有多种类型的单个实体进行建模,每种类型具有不同的属性。 作为示例,假设我想为“数据源”对象创建一个关系模型。所有数据源都会有一些共享属
(1) =>CREATE TABLE T1(id BIGSERIAL PRIMARY KEY, name TEXT); CREATE TABLE (2) =>INSERT INTO T1 (name)
我不确定在使用别名时如何解决不明确的列引用。 假设有两个表,a 和 b,它们都有一个 name 列。如果我加入这两个表并为结果添加别名,我不知道如何为这两个表引用 name 列。我已经尝试了一些变体,
我的查询是: select * from table where id IN (1,5,4,3,2) 我想要的与这个顺序完全相同,不是从1...5,而是从1,5,4,3,2。我怎样才能做到这一点? 最
我正在使用 C# 代码执行动态生成的 MySQL 查询。抛出异常: CREATE TABLE dump ("@employee_OID" VARCHAR(50)); "{"You have an er
我有日期 2016-03-30T23:59:59.000000+0000。我可以知道它的格式是什么吗?因为如果我使用 yyyy-MM-dd'T'HH:mm:ss.SSS,它会抛出异常 最佳答案 Sim
我有一个示例模式,它的 SQL Fiddle 如下: http://sqlfiddle.com/#!2/6816b/2 这个 fiddle 只是根据 where 子句中的条件查询示例数据库,如下所示:
我是一名优秀的程序员,十分优秀!