Domanda

I have gtest up and running using code as shown below. I would like to print the test output to a text file as opposed to displaying it in the console. Is there a way of doing this?

I run the tests using cmake from the console: cmake CMakeLists.txt && make && ./runTests .

#include "cw-test.c"
#include <stdio.h>
#include <gtest/gtest.h>

TEST(InputValidationTest, ValidateEntryLine)
{
    ...
}

...

int main(int argc, char **argv) {
    testing::InitGoogleTest(&argc, argv);
    return RUN_ALL_TESTS();
}
È stato utile?

Soluzione

You can redirect the output of your runTests command to a file:

cmake CMakeLists.txt && make && ./runTests > test_output.txt

Also, see this which explains why you do not need the & I had used in my comment. As Awaken's answer says, the & redirects both the stdout and stderr to the same file. But since googletest output always goes to stdout you may leave out the &.

Altri suggerimenti

crayzeewulf's comment will work for any Unix program. What "&>" means is to redirect output in "stdout" and "stderr" to some other location you specify.

More information can be found here. http://www.mathinfo.u-picardie.fr/asch/f/MeCS/courseware/users/help/general/unix/redirection.html

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top