运行Junit测试时如何修复assertTrue错误

时间:2019-05-14 07:15:40

标签: java junit assert

设置Junit测试,但运行失败。问题似乎在我的assertTrue上

import static org.junit.Assert.*;

import org.junit.Test;

import com.neueda.cap.spark.model.NeuFixMessage;

import quickfix.Message;

public class CalculateFillValue {

    @Test
    public void test() throws Exception {
        CalculateFillValuesMapper test = new CalculateFillValuesMapper();
        NeuFixMessage msg= new  NeuFixMessage();
        msg.setMsgType("8");
        msg.setExecType("1");
        msg.setLastPx("10.10");
        msg.setLastShares("100");

        msg = test.call(msg);
        assertTrue("The  file value should be 1010", msg.getFillValue() == 1010);



    }

}

2 个答案:

答案 0 :(得分:0)

测试失败的唯一原因是getFillValue()返回1010以外的任何内容。将输出打印在assertTrue方法上方,您应该看到测试失败的原因。

System.out.println("Fill Value: " + msg.getFillValue());

boolean testCondition = (msg.getFillValue() == 1010)


System.out.println("testCondition: " + testCondition);

assertTrue("The  file value should be 1010", testCondition);

答案 1 :(得分:0)

使用assertTrue或assertequals更好吗

当前代码为

assertEquals(“这是预期的填充量”,msg.getFillValue(),(1010.0));

错误:类型CalculateFillValue的方法assertEquals(String,Object,Object)含糊不清