java - How to use JUnit assertThat correctly? -
this question has answer here:
- hamcrest tests fail 14 answers
i have class called calculator 4 basic operations of adding, subtracting, dividing , multiplying
public class calculator{ public int add(int a, int b) { return + b; } public int subtract(int a, int b) { return - b; } public double multiply(double a, double b) { return * b; } public double divide(double a, double b) { if (b == 0) { throw new arithmeticexception("division zero."); } return / b; } }
i'm using maven project , pom.xml file:
<project xmlns="http://maven.apache.org/pom/4.0.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://maven.apache.org/pom/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelversion>4.0.0</modelversion> <groupid>br.usp.icmc</groupid> <artifactid>calculadora</artifactid> <version>0.0.1</version> <dependencies> <dependency> <groupid>org.hamcrest</groupid> <artifactid>hamcrest-library</artifactid> <version>1.3</version> </dependency> </dependencies> </project>
i created test in junit follows:
public void testsumwithassertthat() { int expectedvalue = 2; int returnedvalue = calculator.add(1, 1); assertthat(returnedvalue, is(expectedvalue)); }
i'm getting following exception:
java.lang.securityexception: class "org.hamcrest.matchers"'s signer information not match signer information of other classes in same package
why throwing exception? what's going wrong simple code?
make sure hamcrest.jar before junit library included in classpath resolves issue.
Comments
Post a Comment