JUnit - How to test a method with different values?

家住魔仙堡 提交于 2019-12-01 16:21:22
Constantiner

You can take a look at parametrized tests like in example.

You can also use theories which is more convenient in a lot of cases.

JUnit4 supports parameterized tests for just this purpose.

See this tutorial.

I suggest you create a different unit test for each one of your (overloaded) function definitions, because arguably you are testing in fact different functions. For instance:

class MainClass {
public void method( int param) {... }
public void method( String param) { ...}
}

class MainClassTest {
@Test
public void methodIntTest() {
 //call method(int)
}

@Test
public void methodStringTest() {
 //call method(String)
}
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!