В одном пакете есть 2 класса, один из них тестовый
package main;
public class Amount{
public int sum(int v1, int v2){
System.out.println("Adding values " + v1 + " + " + v2);
return v1 + v2;
}
}
package main;
import static org.junit.Assert.*;
import org.junit.Test;
public class AmountTest{
Amount project = new Amount();
int sum = project.sum(2,5);
int resSum = 7;
@Test
public void testSum(){
System.out.println("@TestSum(): " + sum + " = " + resSum);
assertEquals(sum, resSum);
}
}
Но проверка заканчивается неудачно
junit:
[junit] Running main.AmountTest
[junit] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.017 sec
[junit] Test main.AmountTest FAILED
Почему?
ОБНОВЛЕНИЕ
<path id="classpath" location="lib/*.jar">
<fileset dir="lib" includes="*.jar" />
</path>
<path id="application" location="build/jar/Project.jar" />
<target name="junit">
<junit printsummary="yes">
<classpath>
<path refid="classpath" />
<path refid="application" />
</classpath>
<batchtest fork="yes">
<fileset dir="src" includes="**/*Test.java"/>
</batchtest>
</junit>
</target>
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0
, в вашем же случае произошла ошибка, не связанная с ожидаемыми условиями теста, потому у васErrors: 1
.