Junit添加Hamcrest
右击<项目> –> Build Path –> Add External Archives –> 添加core和library 两个jar包
在Junit test class里静态引入:
import static org.hamcrest.Matchers.*
solve SecurityException:
产生Exception的原因主要是因为用到了JUnit4和hamcrest两种包,但是这两个包的classLoader并不是同一个,如果是同一个就没有问题了。解决方案:
把原来eclipse自带的junit的library去掉:
右击
Junit4
–> Build Path里选Remove from Build Path
自己再引入新的包:
右击<项目> –> Build Path –> Add External Archives –> 添加Junit的jar包