Test a specific exception type is thrown AND the exception has the right properties
I mostly second Lilshieste's answer but would add that you also should
verify that the wrong exception type is not thrown:
#include <stdexcept>
#include "gtest/gtest.h"
struct foo
{
int bar(int i) {
if (i > 100) {
throw std::out_of_range("Out of range");
}
return i;
}
};
TEST(foo_test,out_of_range)
{
foo f;
try {
f.bar(111);
FAIL() << "Expected std::out_of_range";
}
catch(std::out_of_range const & err) {
EXPECT_EQ(err.what(),std::string("Out of range"));
}
catch(...) {
FAIL() << "Expected std::out_of_range";
}
}
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
Using SoftAssertion with cucumber
The sa.assertThat() method takes the actual value as parameter, and returns an assertion object that must be checked with one of the available methods. In your example, it must be checked with the isEqualToIgnoringCase(expected) method.
@Given("^I have a scenario for Soft assert$")
public void i_have_a_scenario_for_soft_assert() throws Throwable {
System.out.println("Inside the given of soft assestion.. All Good");
}
@When("^I validate the first step for soft assertion$")
public void i_validate_the_first_step_for_soft_assertion() throws Throwable {
sa = new SoftAssertions();
System.out.println("Executing the FIRST");
sa.assertThat("bal").isEqualToIgnoringCase("BAL");
System.out.println("Executing the SECOND");
sa.assertThat("bal").isEqualToIgnoringCase("AM");
System.out.println("Executing the THIRD");
sa.assertThat("123").isEqualToIgnoringCase("321");
}
@And("^i validate the second step for soft assertion$")
public void i_validate_the_second_step_for_soft_assertion() throws Throwable {
System.out.println("Second validation.. All Good");
}
@Then("^I complete my validation for soft assertion example$")
public void i_complete_my_validation_for_soft_assertion_example() throws Throwable {
sa.assertAll();
System.out.println("Final Validation.. All Good");
}
Related Topics
Rails: Serializing Objects in a Database
Using a Ruby Script to Login to a Website via Https
Array.Include? Multiple Values
Rails How to Switch Between Dev and Production Mode
What Are the Main Differences Between Sinatra and Ramaze
Creating an Empty File in Ruby: "Touch" Equivalent
"Ago" Date/Time Functions in Ruby/Rails
Which Ruby Memoize Pattern Does Activesupport::Memoizable Refer To
How to Check from Ruby Whether a Process with a Certain Pid Is Running
How to Sort a Hash by Value in Descending Order and Output a Hash in Ruby
Ruby/Rails Using || to Determine Value, Using an Empty String Instead of a Nil Value
How to Pass Arguments from the Parent Task to the Child Task in Rake