问题
I want to add a testcase for functionality not yet implemented and mark this test case as "it's ok that I fail".
Is there a way to do this?
EDIT: I want the test to be executed and the framework should verify it is failing as long as the testcase is in the "expected fail" state.
EDIT2: It seems that the feature I am interested in does not exist in google-test, but it does exist in the Boost Unit Test Framework, and in LIT.
回答1:
You can prefix the test name with DISABLED_.
回答2:
I'm not aware of a direct way to do this, but you can fake it with something like this:
try {
// do something that should fail
EXPECT_TRUE(false);
} catch (...) {
// return or print a message, etc.
}
Basically, the test will fail if it reaches the contradictory expectation.
回答3:
It would be unusual to have a unit test in an expected-to-fail state. Unit tests can test for positive conditions ("expect x
to equal 2
") or negative conditions ("expect save
to throw an exception if name
is null
"), and can be flagged not to run at all (if the feature is pending and you don't want the noise in your test output). But what you seem to be asking for is a way to negate a feature's test while you're working on it. This is against the tenants of Test Driven Development.
In TDD, what you should do is write tests that accurately describe what a feature should do. If that feature isn't written yet then, by definition, those tests will and should fail. Then you implement the feature until, one by one, all those tests pass. You want all the tests to start as failing and then move to passing. That's how you know when your feature is complete.
Think of how it would look if you were able to mark failing tests as passing as you suggest: all tests would pass and everything would look complete when the feature didn't work. Then, once you were done and the feature worked as expected, suddenly your tests would start to fail until you went in and unflagged them. Beyond being a strange way to work, this workflow would be very prone to error and false-positives.
来源:https://stackoverflow.com/questions/20785939/how-to-mark-a-google-test-test-case-as-expected-to-fail