8

Is there a recommended way to integrate Hamcrest into the JUnit configuration in Eclipse? Currently Eclipse's JUnit comes with Hamcrest-core only. I want to edit that configuration to include Hamcrest-all. How should I do this?

Hosam Aly
  • 41,555
  • 36
  • 141
  • 182

3 Answers3

1

I had problems using hamcrest-all and junit-dep - you then need jMock an easymock and ant.tasks

If you just want more matchers, add hamcrest-library (along with the junit and hamcrest core you get from Eclipse)

Shouldn't this question have the "hamcrest" tag?

Andrew McKinlay
  • 2,431
  • 1
  • 24
  • 27
  • The tag didn't exist when I created the question IIRC. I've added it now. Thanks for the suggestion. – Hosam Aly Jan 09 '11 at 09:17
  • After I posted this I ran into a problem with this approach. I get a SecurityException. Apparently this is because the Eclipse hamcrest-core is signed but the hamcrest-library I added isn't. Supposedly the solution is to put the unsigned one first in the build path but that didn't fix it for me. – Andrew McKinlay Jan 09 '11 at 18:50
0

There's nothing to stop you adding hamcrest as a JAR to your eclipse project's build path. If there's one packaged with eclipse (and I didn't realise there was, but fair enough), then it's just there as a convenience.

skaffman
  • 398,947
  • 96
  • 818
  • 769
  • Yes, I could always add it as a library, but I was hoping to find a way to embed it into JUnit's configuration, so that it's automatically added to all (existing and new) projects that use JUnit. – Hosam Aly Jul 06 '09 at 12:47
  • 1
    This doesn't actually work. Hamcrest adds some of the same classes that JUnit is providing, thus leading to SecurityExceptions. – nes1983 Sep 28 '11 at 11:52
0

JUnit goes in two distributions: with Hamcrest (junit-4.6.jar) and without Hamcrest (junit-dep-4.6.jar). If I understand your question correctly, you need to specify junit-4.6.jar in JUnit configuration. I think it is possible in Eclipse (I use another IDE).

Rorick
  • 8,857
  • 3
  • 32
  • 37
  • It seems to me that JUnit only includes hamcrest-core, while I am trying to integrate hamcrest-all into Eclipse. – Hosam Aly Jul 06 '09 at 13:00
  • You're right. Probably you can build your own junit.jar with embedded classes from hamcrest-all.jar and replace junit.jar in JUnit eclipse plugin with it. I'm not sure it is a good idea, but you can try. – Rorick Jul 06 '09 at 13:08
  • 1
    Yes, I believe this would work, but I don't think it's the "recommended" way of doing it. :) – Hosam Aly Jul 06 '09 at 13:30