Questions tagged [expected-exception]

90 questions
42
votes
7 answers

How do I get SpecFlow to expect an exception?

I'm using SpecFlow, and I'd like to write a scenario such as the following: Scenario: Pressing add with an empty stack throws an exception Given I have entered nothing into the calculator When I press add Then it should throw an…
Roger Lipscombe
  • 89,048
  • 55
  • 235
  • 380
34
votes
8 answers

How do I enforce exception message with ExpectedException attribute

I thought these two tests should behave identically, in fact I have written the test in my project using MS Test only to find out now that it does not respect the expected message in the same way that NUnit does. NUnit (fails): [Test,…
CRice
  • 12,279
  • 7
  • 57
  • 84
28
votes
1 answer

ExpectedException Attribute Usage

I am trying to work with the ExpectedException attribute in a C# UnitTest, but I am having issues getting it to work with my particular Exception. Here's what I got: NOTE: I wrapped asterisks around the line that is giving me the trouble. …
Jonathan
  • 589
  • 1
  • 13
  • 23
23
votes
4 answers

How to continue test after JUnit ExpectedException if thrown?

I have set up some JUnit (4.12) test with the ExpectedException feature, and I would like the test to continue after the expected exception. But I never see the log '3', as the execution seems to stop after the exception, event if catch? Is this…
Deathtiny
  • 728
  • 3
  • 8
  • 14
11
votes
5 answers

ExpectedException Assert

I need to write a unit test for the next function and I saw I can use [ExpectedException] this is the function to be tested. public static T FailIfEnumIsNotDefined(this T enumValue, string message = null) where T:struct { var…
Rubenex
  • 469
  • 2
  • 8
  • 23
9
votes
1 answer

Strange behavior with NUnit, ExpectedException & yield return

I have a strange behavior in a tests where I want to test that an exception is thrown when null is passed in as a parameter. When I run the test I get from NUnit: System.ArgumentNullException was expected -- Exception doesn't have a stack…
mr carl
  • 571
  • 2
  • 6
  • 20
9
votes
4 answers

CodeCoverage vs ExpectedException

I've got several unittests of this pattern: [TestMethod ()] [ExpectedException (typeof (ArgumentNullException))] public void DoStuffTest_Exception () { var foo = new Foo (); Foo.DoStuff (null); } It turns out that code coverage markes the…
mafu
  • 31,798
  • 42
  • 154
  • 247
8
votes
3 answers

ExpectedException cause of the cause?

I'm trying to verify that all my exceptions are correct. Because values are wrapped in CompletableFutures, the exception thrown is ExecutionException with cause being the exception that I would normally check. Quick example: void foo() throws A { …
Amir
  • 717
  • 2
  • 9
  • 21
8
votes
5 answers

ExpectedExceptionAttribute is not working in MSTest

This is weird, but all of a sudden the ExpectedExceptionAttribute quit working for me the other day. Not sure what's gone wrong. I'm running VS 2010 and VS 2005 side-by-side. It's not working in VS 2010. This test should pass, however it is…
Micah
  • 111,873
  • 86
  • 233
  • 325
8
votes
3 answers

ExpectedException in jUnit?

Is there an equivalent to NUnit's ExpectedException or Assert.Throws<> in jUnit?
ripper234
  • 222,824
  • 274
  • 634
  • 905
7
votes
3 answers

Android Release error: Expected a color resource id (R.color.) but received an RGB integer

I have an application in the market for a year. Last week, I have changed the source code of my app. When I wanted to build the release version Android Studio throws an Error: "Error: Expected a color resource id (R.color.) but received an RGB…
ADSC
  • 71
  • 1
  • 3
7
votes
1 answer

How can I test several exceptions within one test using an ExpectedException Rule?

Got a question regarding the usage of junit's ExpectedException rule: As suggested here: junit ExpectedException Rule starting from junit 4.7 one can test exceptions like this (which is much better then the…
Lonzak
  • 9,334
  • 5
  • 57
  • 88
6
votes
3 answers

How to work with junit ExpectedException?

I'm trying to work with ExpectedExceptions for JUnit. I tried already this: public class ExpectedTest { @Rule public ExpectedException thrown = ExpectedException.none(); @Test public void test() { …
Rafael T
  • 15,401
  • 15
  • 83
  • 144
6
votes
1 answer

@ExpectedException in grails unit tests

Anyone used this annotation in grails unit tests? Didnt seem to work for me. Thanks. D Update: the last line of my test below does throw the expected exception. However the test fails (Stack trace too big for here...). I'm using grails 1.2 and…
Derek
  • 760
  • 2
  • 11
  • 20
5
votes
3 answers

Exception in MS Unit Test?

I created a unit test for a method of my project. That method raises an exception when a file is not found. I wrote a unit test for that, but I'm still not able to pass the test when the exception is raised. Method is public string[]…
PawanS
  • 7,033
  • 14
  • 43
  • 71
1
2 3 4 5 6