expected-exception

Exception handling and testing with pytest and hypothesis

☆樱花仙子☆ 提交于 2021-01-28 06:46:08
问题 I'm writing tests for a statistical analysis with hypothesis. Hypothesis led me to a ZeroDivisionError in my code when it is passed very sparse data. So I adapted my code to handle the exception; in my case, that means log the reason and reraise the exception. try: val = calc(data) except ZeroDivisionError: logger.error(f"check data: {data}, too sparse") raise I need to pass the exception up through the call stack because the top-level caller needs to know there was an exception so that it

ExpectedException Attribute Usage

青春壹個敷衍的年華 提交于 2020-01-12 03:06:48
问题 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 //

PHPUnit: continue after die, expect “die” or somehow handle die()? [duplicate]

為{幸葍}努か 提交于 2019-12-24 00:58:59
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: How do you use PHPUnit to test a function if that function is supposed to kill PHP? I'm writing some unit tests. The system I'm currently testing is a web-app in an MVC framework. If we want to render pages without the site-skin system we've traditionally run our code as usual, but printed a "die();" statement at the end of the function to exit before the rest of the website renders. Well now that we're adding

ExpectedExceptionAttribute is not working in MSTest

我只是一个虾纸丫 提交于 2019-12-21 04:50:42
问题 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. 回答1: Not to resurrect a dead thread, but I came across this when this all the

How can I use JUnit's ExpectedException to check the state that's only on a child Exception?

柔情痞子 提交于 2019-12-11 03:33:16
问题 I'm trying to refactor this old code that does not use ExpectedException so that it does use it: try { //... fail(); } catch (UniformInterfaceException e) { assertEquals(404, e.getResponse().getStatus()); assertEquals("Could not find facility for aliasScope = DOESNTEXIST", e.getResponse().getEntity(String.class)); } And I can't figure out how to do this because I don't know how to check the value of e.getResponse().getStatus() or e.getResponse().getEntity(String.class) in an ExpectedException

ExpectedException Assert

你离开我真会死。 提交于 2019-12-09 16:04:27
问题 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)) {

Multiple expected exceptions in JUnit

本小妞迷上赌 提交于 2019-12-07 10:03:18
问题 The application is throwing 2 different exceptions in some thatMethod(). I'm looking to test it by JUnit. I can use ExpectedException and @Rule to set aside a "natural" exception the application is expected to throw. How do you assert that a certain exception is thrown in JUnit 4 tests? is explaining this. How can i do that in my case-- 2 or more " natural " exceptions? ExpectedException is not holding multiple expected exceptions. There are other ways to do this-- as explained in How do you

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

守給你的承諾、 提交于 2019-12-07 09:33:49
问题 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. 回答1: To avoid anyone else hunting around for ages trying to find it, here's the solution: [Test, ExpectedException( ArgumentOutOfRangeException::typeid )] void Test

Multiple expected exceptions in JUnit

守給你的承諾、 提交于 2019-12-05 17:24:59
The application is throwing 2 different exceptions in some thatMethod(). I'm looking to test it by JUnit. I can use ExpectedException and @Rule to set aside a "natural" exception the application is expected to throw. How do you assert that a certain exception is thrown in JUnit 4 tests? is explaining this. How can i do that in my case-- 2 or more " natural " exceptions? ExpectedException is not holding multiple expected exceptions. There are other ways to do this-- as explained in How do you assert that a certain exception is thrown in JUnit 4 tests? again. i'm wondering whether there is a way