c++ - How to use a return value from a gtest to another test -


i trying test c++ program via google test framework.

my code:

int addnumbers(int a, int b) {     return + b; }  int subtractnumbers(int a, int b) {     return - b; } 

unit test code:

//first test test(testmath, addtest1) {     expect_eq(37, addnumbers(14, 23));     getchar(); }  //second test test(testmath, subtracttest1) {     expect_eq(25, subtractnumbers(37, 12));     getchar(); }  //third test test(testmath, addtest2) {     expect_eq(62, addnumbers(37, 25));     getchar(); } 

but, need unit test in different way.

my expectation: need return value (result) of first test , use in second test dynamic (if first test failed, program should terminate showing error details). when first test , second test ok (not failed), return values first , second test should parameterized third test.

desired algorithm (as you):

step 1: run first test addnumbers(14, 23);

step 2: check expected , return values(a);

step 3.1: if test failed, terminate program showing error details;

step 3.2: if ok (not failed), run second test subtractnumbers(a, 12);

step 4: check expected , return values(b);

step 5.1: if test failed, terminate program showing ok details , error details;

step 5.2: if ok (not failed), run third test addnumbers(a,b);

step 6: check expected , return values;

step 7.1: if test failed, terminate program showing ok details , error details;

step 7.2: if ok, show ok details.

using various assert_* macros cause test abort on failure. can convert expect_eq assert_eq, place them within same test().

test(testmath, testall) {   auto = addnumbers(14, 23);   assert_eq(37, a);   auto b = subtractnumbers(a, 12)   assert_eq(25, b);   assert_eq(62, addnumbers(a, b)); } 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -