Junit中使用hamcrest

来源:互联网 发布:有百合网源码卖 编辑:程序博客网 时间:2024/05/21 11:28

Junit添加Hamcrest

  1. 右击<项目> –> Build Path –> Add External Archives –> 添加corelibrary 两个jar包

  2. 在Junit test class里静态引入:

    import static org.hamcrest.Matchers.*
  3. solve SecurityException:
    产生Exception的原因主要是因为用到了JUnit4和hamcrest两种包,但是这两个包的classLoader并不是同一个,如果是同一个就没有问题了。

    解决方案:

    1. 把原来eclipse自带的junit的library去掉:

      右击Junit4 –> Build Path里选Remove from Build Path

    2. 自己再引入新的包:

      右击<项目> –> Build Path –> Add External Archives –> 添加Junit的jar包

0 0
原创粉丝点击