[Test] Problem with expected failures in test suite

Hello, I tried to write a test suite with one expected failure, however it is not working. Probably I'm doing something wrong. The idea is that I have a function that can be implemented in few ways, thus there are few possible correct results. Depending on the implementation, I want to test it with different set of test cases. I don't want to check at the beginning of each test case which option is valid, I would prefer to skip unnecessary test cases. Is it possible? The simplified code is below: bool xxx = ...; // opt1 and opt2: two exclusive options // one of them always passes and one always fails void opt1(){ BOOST_CHECK(xxx); } void opt2(){ BOOST_CHECK(!xxx); } void test1_1(){ } test_suite* init_unit_test_suite( int argc, char* argv[] ) { test_case* opt1_case = BOOST_TEST_CASE(&opt1); test_case* opt2_case = BOOST_TEST_CASE(&opt2); test_suite* dichotomic_test = BOOST_TEST_SUITE( "dichotomic test" ); framework::master_test_suite().add(dichotomic_test); dichotomic_test->add( opt1_case ); dichotomic_test->add( opt2_case ); // I want exactly one of them to fail dichotomic_test->increase_exp_fail(1); test_case* case1_1 = BOOST_TEST_CASE(&test1_1); case1_1->depends_on(opt1_case); framework::master_test_suite().add(case1_1); } I'll be thankful for help, Maria

AMDG Maria Kozinska wrote:
I tried to write a test suite with one expected failure, however it is not working.
How is it not working? The output looks right to me: Running 3 test cases... c:/documents and settings/steven/my documents/visual studio 2010/projects/scratc h/scratch/scratch.cpp(13): error in "opt2": check !xxx failed *** 1 failure detected (1 failure expected) in test suite "Master Test Suite" What do you expect to see?
Probably I'm doing something wrong. The idea is that I have a function that can be implemented in few ways, thus there are few possible correct results. Depending on the implementation, I want to test it with different set of test cases. I don't want to check at the beginning of each test case which option is valid, I would prefer to skip unnecessary test cases. Is it possible?
In init_unit_test_suite, can you try only adding the test cases that you need? In Christ, Steven Watanabe

Thanks for answer.
On 4 June 2010 00:27, Steven Watanabe
AMDG
Maria Kozinska wrote:
I tried to write a test suite with one expected failure, however it is not working.
How is it not working? The output looks right to me: Running 3 test cases... c:/documents and settings/steven/my documents/visual studio 2010/projects/scratc h/scratch/scratch.cpp(13): error in "opt2": check !xxx failed
*** 1 failure detected (1 failure expected) in test suite "Master Test Suite"
What do you expect to see?
With --report_level=short I can see that "Master Test Suite" failed despite 1 failure expected. I would like it to pass, because this exactly one failure is OK. Running 3 test cases... sample.cxx(14): error in "opt2": check !xxx failed Test suite "Master Test Suite" failed with: 1 assertion out of 2 passed 1 assertion out of 2 failed 1 failure expected 2 test cases out of 3 passed 1 test case out of 3 failed
Probably I'm doing something wrong. The idea is that I have a function that can be implemented in few ways, thus there are few possible correct results. Depending on the implementation, I want to test it with different set of test cases. I don't want to check at the beginning of each test case which option is valid, I would prefer to skip unnecessary test cases. Is it possible?
In init_unit_test_suite, can you try only adding the test cases that you need?
I have to add all of them, because at compile time I don't know yet which ones should be executed. It is ensured at runtime by dependencies - as with test1_1, which is executed only if option1 succeeded (and skipped otherwise). Maria

Maria Kozinska wrote:
Thanks for answer.
On 4 June 2010 00:27, Steven Watanabe
wrote: AMDG
Maria Kozinska wrote:
I tried to write a test suite with one expected failure, however it is not working.
Apparently expected failures do not work with test suites properly. The issue is that the reporting function validate both expected failures AND failed test cases within the test unit. In your case at least one test case will always fail and we do not have option to tell that one test case is expected to fail. I guess I can skip test case check, but in this case you may get into the weird false positives with test suite passing when you actually it expected to fail. For example you expected 2 failures in 1 test case, but you got them in 2 different test cases. Another option is to treat "expected failures" for test suite as expected number of failed test cases, but this really changes semantic thus is not backward compatible change. Not sure if anyone uses current semantic (though it's obviously broken and never worked from what I can tell)
The idea is that I have a function that can be implemented in few ways, thus there are few possible correct results. Depending on the implementation, I want to test it with different set of test cases. I don't want to check at the beginning of each test case which option is valid, I would prefer to skip unnecessary test cases. Is it possible?
In init_unit_test_suite, can you try only adding the test cases that you need? I have to add all of them, because at compile time I don't know yet which ones should be executed. It is ensured at runtime by dependencies - as with test1_1, which is executed only if option1 succeeded (and skipped otherwise).
Why don't you put everything in a single test case and switch based on the value of xxx to do one set of tests or another? Gennadiy
participants (3)
-
Gennadiy Rozental
-
Maria Kozinska
-
Steven Watanabe