整数的AssertTrue vs AssertEquals [英] AssertTrue vs AssertEquals for ints

查看:170
本文介绍了整数的AssertTrue vs AssertEquals的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们应该使用assertEquals或assertTrue来比较原始类型(特别是int)吗? 是否有偏好,如果可以,为什么?我想知道每种方法的利弊.

Should we use assertEquals or assertTrue for comparing primitive types specifically ints? Is there a preference, if so why ? I'd like to know the pros and cons of each approach.

推荐答案

assertEquals()在失败时给出有用的默认错误消息,例如期望X但得到Y",但assertTrue()不能.在这里使用更具体的适用方法,即assertEquals().

assertEquals() gives a useful default error message on failure, like "expected X but got Y", but assertTrue() can't. Use the more specific applicable method here, which is assertEquals().

这篇关于整数的AssertTrue vs AssertEquals的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆