c# - Assert one exception OR the other -
let's i've got test methods a, b, c. when launch them all, test method b throws sqliteexception , green , ok.
assert.throws<sqliteexception>(() => sql.select(selectfrom + "table_name"));
but, when i'm launching test method b throws argumentexception before sqliteexception , test fails.
the question is: how assert 1 or other exception thrown?
i'm talking this
assert.throws<sqliteexception>(() => sql.select(selectfrom + "table_name")).or.throws<argumentexception>()
try { somethingthatshouldthrowanacception(); assert.fail(); // if gets line, no exception thrown } catch (goodexception) { }
you should able adapt approach whatever like, including specific exceptions want catch. if expect types, finish catch blocks off with:
} catch (goodexception) { } catch (exception) { // don't want exception assert.fail(); }
remember can't this
try { somethingthatshouldthrowanacception(); assert.fail(); } catch (exception) { }
because assert.fail() works throwing assertionexception.
you can this
try { somethingthatshouldthrowanacception(); assert.fail("no exception thrown"); } catch (exception ex) { assert.istrue(ex specificexceptiontype); }
Comments
Post a Comment