expected-exception

How do I use ExpectedException in C++/CLI NUnit tests?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-05 12:38:00
How do you do the equivalent of: [Test, ExpectedException( typeof(ArgumentOutOfRangeException) )] void Test_Something_That_Throws_Exception() { throw gcnew ArgumentOutOfRangeException("Some more detail"); } ...in C++ (the example there is C#)? As far as I can see, there's no typeof() function for the C++ implementation of NUnit. To avoid anyone else hunting around for ages trying to find it, here's the solution: [Test, ExpectedException( ArgumentOutOfRangeException::typeid )] void Test_Something_That_Throws_Exception() { throw gcnew ArgumentOutOfRangeException("Some more detail"); } Simply use

ExpectedException Assert

情到浓时终转凉″ 提交于 2019-12-05 03:23:56
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<T>(this T enumValue, string message = null) where T:struct { var enumType = typeof (T); if (!enumType.IsEnum) { throw new ArgumentOutOfRangeException(string.Format("Type {0} is not an Enum, therefore it cannot be checked if it is Defined not have defined.", enumType.FullName)); } else if (!Enum.IsDefined(enumType, enumValue)) { throw new ArgumentOutOfRangeException(string.Format("{1} Value {0} is not does not have defined value in

ExpectedExceptionAttribute is not working in MSTest

不打扰是莪最后的温柔 提交于 2019-12-03 14:24:50
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 failing: [TestMethod] [ExpectedException(typeof(ArgumentNullException))] public void Test_Exception() { throw new ArgumentNullException("test"); } Any ideas? This really sux. Steve Py Not to resurrect a dead thread, but I came across this when this all the sudden happened to me, in case it can help others. I did finally track down what the problem was,

ExpectedException Attribute Usage

元气小坏坏 提交于 2019-12-03 05:34:43
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. [ExpectedException(typeof(Exception))] public void TestSetCellContentsTwo() { // Create a new Spreadsheet instance for this test: SpreadSheet = new Spreadsheet(); // If name is null then an InvalidNameException should be thrown. Assert that the correct // exception was thrown. ReturnVal = SpreadSheet.SetCellContents(null, "String Text"); **Assert.IsTrue

How do I get SpecFlow to expect an exception?

陌路散爱 提交于 2019-12-03 04:43:37
问题 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 exception It's calculator.Add() that's going to throw an exception, so how do I handle this in the method marked [Then] ? 回答1: Great question. I am neither a bdd or specflow expert, however, my first bit of advice would be to take a step back and assess your scenario.

Why won't this Expect Exception Junit Test Work?

ぃ、小莉子 提交于 2019-12-02 20:31:45
问题 This is my test so far: @Test(expected = FileNotFoundException.class) public void testExpectedException() { UserDataObject u = new UserDataObject("rob123", "Smith", "Robert", "Danny", 1); FlatFileStorage ffstorage = new FlatFileStorage(); ffstorage.verifyUser(u, "dsfsdfsfdsdf.txt"); However, the test seems to fail! Even though when I run it, the error message actually gets printed out from the method on the console too, like this dsfsdfsfdsdf.txt (The system cannot find the file specified) Am

How do I get SpecFlow to expect an exception?

青春壹個敷衍的年華 提交于 2019-12-02 19:01:56
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 exception It's calculator.Add() that's going to throw an exception, so how do I handle this in the method marked [Then] ? Great question. I am neither a bdd or specflow expert, however, my first bit of advice would be to take a step back and assess your scenario. Do you really want to use the terms "throw" and "exception" in this spec? Keep in mind the idea with bdd is

Why won't this Expect Exception Junit Test Work?

前提是你 提交于 2019-12-02 09:14:10
This is my test so far: @Test(expected = FileNotFoundException.class) public void testExpectedException() { UserDataObject u = new UserDataObject("rob123", "Smith", "Robert", "Danny", 1); FlatFileStorage ffstorage = new FlatFileStorage(); ffstorage.verifyUser(u, "dsfsdfsfdsdf.txt"); However, the test seems to fail! Even though when I run it, the error message actually gets printed out from the method on the console too, like this dsfsdfsfdsdf.txt (The system cannot find the file specified) Am I missing something really obvious here? EDIT** Here is the method I'm actually testing public void

How to continue test after JUnit ExpectedException if thrown?

末鹿安然 提交于 2019-11-30 22:08:28
问题 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 actually possible, and how? @Rule public ExpectedException exception = ExpectedException.none(); @Test public void testUserAlreadyExists() throws Exception { log.info("1"); // Create some users userService.createUser("toto1"); userService.createUser(