Questions tagged [expected-exception]
90 questions
4
votes
1 answer
Exception handling and testing with pytest and hypothesis
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…

suvayu
- 4,271
- 2
- 29
- 35
4
votes
3 answers
JUnit 4 : Expect one exception multiple times
I have the following piece of code:
@Test(expected = IllegalArgumentException.class)
public void failureTest() {
testedObject.supposedToFail("");
testedObject.supposedToFail(null);
}
When running this, I have no guarantee that I will…

Yassine Badache
- 1,810
- 1
- 19
- 38
4
votes
2 answers
NUnit - ExpectedMessage differs error
I am quite new to TDD and am going with NUnit and Moq. I have got a method where I expect an exception, so I wanted to play a little with the frameworks features.
My test code looks as follows:
[Test]
[ExpectedException(ExpectedException =…

Mark
- 7,891
- 5
- 27
- 36
4
votes
3 answers
Multiple expected exceptions in JUnit
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…

Roam
- 4,831
- 9
- 43
- 72
4
votes
1 answer
How do I use ExpectedException in C++/CLI NUnit tests?
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#)?…

Jon Cage
- 36,366
- 38
- 137
- 215
3
votes
1 answer
Strange Compiler Error, stating that my iterator is undefined
I'm trying to create a template function which will iterate through the map's specified key/value pairs and check to see if there exists any keys specified in the function's parameters.
The implementation looks as follows:
Code
template < class Key,…

zeboidlund
- 9,731
- 31
- 118
- 180
3
votes
3 answers
Selenium will not load full DOM tree, just the page source
I have tried several answers in Stack Overflow. When I print the webpage I can only see the equivalent of viewing the page source in Chrome, rather than the full DOM tree you would get from inspecting the web page. As you can see I have put a wait…

Gabriel
- 31
- 1
- 3
3
votes
1 answer
Is it possible to expect a cause with a cause by using JUnit?
If I expect an exception with some cause I can check it with:
exception.expectCause(IsInstanceOf.instanceOf(MyExceptionB.class));
How do I check an exception with a cause with a cause?
I.e. I have an exception MyExceptionA with a cause MyExceptionB…

Oleksandr
- 3,574
- 8
- 41
- 78
3
votes
1 answer
XUnit and MSTest with ExpectedException Returning Different Results
I have a project that is using a yield return and do not understand why XUnit is failing to catch an exception in my unit test while MSTest is passing.
Here is my dummy code.
The bizarre thing is that if I take my private method,…

Michael A.
- 193
- 9
3
votes
1 answer
Trouble with multiline if statments in OCaml
I wasn't able to find a clear answer on Google, but it seems multiline if-statements are discouraged in OCaml (?) The ones I see with multiple lines seem to have begin end keywords in them.
I'm currently getting this error on the line num = (num -…

stumped
- 3,235
- 7
- 43
- 76
3
votes
0 answers
MSTest: why is TestOutcome = InProgress after ExpectedCondition?
I have the following tryout code:
[TestMethod]
public void VisibilitySucces()
{
testPage.HideParagraph();
testPage.ShowParagraph();
}
[TestMethod, ExpectedException(typeof(WebDriverTimeoutException))]
public void…

FDM
- 628
- 6
- 18
3
votes
1 answer
Set expectedExceptions using dataprovider
Is it possible to set the expectedExceptions option in a TestNG @Test from a @DataProvider? If so, how is it done?
Here is a non-intuitive example:
@DataProvider
private Object[][] methodABadArgsProvider() {
return new Object[][] {
{null,…

ishan3243
- 1,870
- 4
- 30
- 49
3
votes
2 answers
Junit ExpectedException fail with explanatory message
In a junit class, I want to test that an exception is thrown, and if not, provide an explanatory message suggesting what to look for if the test fails. So, something like...
thrown.expect(UnsupportedOperationException.class);
…

Bill Turner
- 869
- 1
- 13
- 27
2
votes
1 answer
Test with UnhandledPromiseRejectionWarning but passing
I'm testing whether a xml2js is returning the same JS as expected. If I run the code when the expected is equal to the received, I get no errors. However, if I run the code when there are differences, I get:
Test Suites: 1 passed, 1 total
Tests: …

malarres
- 2,941
- 1
- 21
- 35
2
votes
2 answers
Lua, setting default function parameter values. This can't be wrong?
Eclipse is telling me that ')' is expected near '=', but surely that can't be right? This is my code:
Animator = Class{}
function Animator:init(statictilesize = true)
self.isTileSizeStatic = statictilesize
end
I'm so confused. I've only been…

John Lardinois
- 109
- 2
- 11