ExpectedException doesn't work well

568 views
Skip to first unread message

eYeScReAmFM

unread,
Jul 21, 2016, 3:57:49 AM7/21/16
to mockito
Hi there,
i've just found 2 issues:
---1. for the following code example (assume it's a nominal test case, i.e. the test should pass):

@Rule
public ExpectedException expectedException = ExpectedException.none();

...

@Test
public void test() {
    expectedException.expect(IllegalArgumentException.class);
    expectedException.expectMessage("Abc!");
    ...
}


the following exception is thrown:

java.lang.NoSuchMethodError: org.hamcrest.Matcher.describeMismatch(Ljava/lang/Object;Lorg/hamcrest/Description;)V

it is caused by another NoSuchMethodError: org.hamcrest.CoreMatchers.containsString(Ljava/lang/String;)

I've checked expectMessage method, and, indeed, it has a reference to CoreMatchers.containsString which doesn't appear in mockito implementation.

The versions I use are: junit-4.11, mockito-all-1.10.8, hamcrest-core-1.3, but I've checked also with junit-4.12 and mockito-all-1.10.19, mockito-all-2.0.2-beta.

Workaround is to use

    expectedException.expectMessage(equalTo("Abc!"));


---2. But! even with the 1st problem worked around, in the error case, i.e. when the test fails, it always fails with the same exception:

java.lang.NoSuchMethodError: org.hamcrest.Matcher.describeMismatch(Ljava/lang/Object;Lorg/hamcrest/Description;)V

Could you investigate and fix this?

Szczepan Faber

unread,
Jul 25, 2016, 5:35:07 PM7/25/16
to mockito
Mockito team does not maintain ExpectedException. It's a part of JUnit. Please reach out to the JUnit team.

Cheers!

--
You received this message because you are subscribed to the Google Groups "mockito" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mockito+u...@googlegroups.com.
To post to this group, send email to moc...@googlegroups.com.
Visit this group at https://groups.google.com/group/mockito.
To view this discussion on the web visit https://groups.google.com/d/msgid/mockito/fb812f79-0d76-4477-be6c-6379347fdacc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Brice Dutheil

unread,
Jul 26, 2016, 7:00:13 AM7/26/16
to moc...@googlegroups.com
Hi eYeScReAmFM,

Don't import mockito-all dependency, it's made for ant users. Maven users should import mockito-core, then you can better manage hamcrest dependencies.
Also if testing Mockito 2.x beta you may want to test the latest released version which is at the time of this reply 2.0.90-beta.

Cheers,
-- Brice

Reply all
Reply to author
Forward
0 new messages