I have a c++ project which has a test suite with already configured scripts. if i run ctest -V it normally check all test available in a directory.
I have written a new test and saved it in the same directory but if I run ctest -V -R newtest , i get the following message.
UpdateCTestConfiguration from :/home/user/project/DartConfiguration.tcl
Constructing a list of tests
Done constructing a list of tests
Checking test dependency graph...
Checking test dependency graph end
No tests were found!!!
I could not find DartConfiguration.tc` file anywhere.
Please help , I am new to ctest or cmake.
Related
If I have a bunch of tests for my project, I can run them - after cmakeing and makeing to build, building - with make test.
But what if I only want to run one of my tests? That is, one of the items for which I have a add_test() in the tests CMakeFile.txt ?
tl;dr - Do this:
cd $YOUR_BUILD_DIRECTORY
ctest -R name_of_your_test
Explanation
Here is how you likely got confused:
You were trying to do this with make, since make test runs all the tests for you. This won't work for a single test (although there's a workaround - see #danger89's answer). ctest is the cross-platform way to do it.
You started using ctest, e.g. in your main project directory, and you probably got something like:
*********************************
No test configuration file found!
*********************************
Usage
ctest [options]
which wasn't helpful.
... So you thought "Ok, maybe ctest has a -C switch, like CMake and GNU Make" - and indeed, it has a -C switch! but that didn't do what you expected:
[joeuser:/home/joeuser/src/myproj]$ ctest -C build
Test project /home/joeuser/src/myproj
No tests were found!!!
What you actually need to do:
cd $YOUR_BUILD_DIRECTORY
ctest -R name_of_your_test
(note that -R matches a regular expression.) This should work. Note that you can list the tests to be run rather than actually run them by passing -N to ctest.
Thanks goes to #RTsyvarev for pointing me in the right direction
einpoklum is not fully correct. Actually you can use make test if you like. CMake will generate a Makefile and I found out that it accepts an ARGS variable.
Meaning you are able run specific tests via for example the -R (regex) parameter. Which will look like this when using make test:
make test ARGS="-R '^test_'"
This will run only the testcases files that starts with test_ in their filename.
Note: -R above is just an example, it will accept all the arguments that ctest command will accept as well.
Anyway the make test example above will do exactly the same as running:
ctest -R '^test_'
I have a Go application with a number of unit and benchmark tests both in the root and in a subfolder called "message".
I execute the following command to run all unit tests from the root including the ones in the messages and any other subfolder:
go test ./...
I want to achieve the same for the benchmark tests, i.e. run them all. The following works for the ones in the root directory:
go test -bench .
The benchmark tests in the /messages folder are ignored which is expected. So I run the following from the root:
go test -bench ./...
That's not recognised at all, Go seems to execute the unit tests that are located in the root dir. I even tried to specify the message folder in the command as follows:
go test -bench ./message
...but it also failed. Currently if I want to run the benchmark tests in the message folder I have to cd into that folder and execute
go test -bench .
like above.
So what's the correct way then? How can I tell Go to find the benchmark tests both in the root and the subfolders? How does the regexp arg work in the case of the -bench flag? Apparently it's different from the regexp for the unit test runner.
You should use ./... to bench all the files from the current working directory and all of its subdirectories. If you wish to get a more verbose output you can use the -v flag. Also it's good to list the memory allocation by using -benchmem.
go test -v ./... -bench=. -run=xxx -benchmem
-bench flag takes regex so to run all benchmarks (-bench .) in all packages: go test -bench=. ./...
I would like to pass parameters to our Catch2 tests via ctest when running through bamboo or jenkins so that they product junit test results. So I would like to do something like:
make test ARGS="-r junit -o test_results.xml"
That would forward these on to my test:
unittest -r junit -o test_results.xml
That way when I run make tests it just runs the tests normally which pretty prints results to the console.
I know args can be added in the add_test() command but I'm looking for something more dynamic.
I'm hoping there is a way to do this in modern CMake.
I have a project structure like this:
pkg
|
--pkg.go
--pkg_test.go
--a.go
--a_test.go
--b.go
--b_test.go
--c.go
--c_test.go
I wish to get the coverage for all the source files belonging to the package i.e.(pkg.go, a.go, b.go and c.go). However, when I run:
go test -v pkg
tests are run for only 1/4 go files.
Is there any way I can test my package without moving all the test codes within one file and keeping the file structure intact ?
if your working directory is that of your package, to test all of the files you could run:
go test ./...
if you wanted to get test coverage, you could run:
go test ./... -cover
I am maintaining an autoconf package and wanted to integrate automatic testing. I use the Boost Unit Test Framework for my unit tests and was able to sucessfully integrate it into the package.
That is it can be compiled via make check, but is is not run (although I read that make check both compiles and runs the tests). As result, I have to run it manually after building the tests which is cumbersome.
Makefile.am in the test folder looks like this:
check_PROGRAMS = prog_test
prog_test_SOURCES = test_main.cpp ../src/class1.cpp class1_test.cpp class2.cpp ../src/class2_test.cpp ../src/class3.cpp ../src/class4.cpp
prog_test_LDADD = $(BOOST_FILESYSTEM_LIB) $(BOOST_SYSTEM_LIB) $(BOOST_UNIT_TEST_FRAMEWORK_LIB)
Makefile.am in the root folder:
SUBDIRS = src test
dist_doc_DATA = README
ACLOCAL_AMFLAGS = ${ACLOCAL_FLAGS} -I m4
Running test/prog yields the output:
Running 4 test cases...
*** No errors detected
(I don't think you need the contents of my test cases in order to answer my question, so I omitted them for now)
So how can I make automake run my tests every time I run make check?
At least one way of doing this involves setting TESTS variable. Here's what documentation on automake says about it:
If the special variable TESTS is defined, its value is taken to be a list of programs or scripts to run in order to do the testing.
So adding the line
TESTS = $(check_PROGRAMS)
should instruct it to run the tests on make check.