在JUnit 5测试中,我如何测试一个数字是正数、负数还是两者混合?

huangapple go评论52阅读模式
英文:

In JUnit 5 test, how can I test a number whether it is positve or negative or a mix of both?

问题

我对JUnit测试还不熟悉。我尝试过使用条件,但似乎在使用assertEquals时没有起作用。例如,assertEquals(1 > 0, 10),这导致测试未通过。有没有其他方法可以做到呢?谢谢。

英文:

I'm new to JUnit testing. I've tried using conditions, but it doesn't seem to work using assertEquals. For example, assertEquals(1 > 0, 10) which gives me a failed test. Is there another way of doing it? Thanks.

答案1

得分: 4

使用 assertTrue,在你的情况下:assertTrue(x > 0)。

你可以在这里找到所有提供的断言类型:这里

英文:

Use assertTrue, in your case: assertTrue(x > 0).

You can find all provided assertion-types here.

huangapple
  • 本文由 发表于 2020年10月10日 03:08:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/64285970.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定