为什么Junit测试用例(方法)应该公开? [英] Why Junit test cases(Methods) should be public?
问题描述
我只想知道为什么测试用例(测试方法)应该公开 像这样
I just want to know why the test cases (test methods) should be public like this
public class SpiceLoginTest {
@Test
public void testShouldVerifyLoginRequest() {
}
}
但是如果我从此方法中删除公共访问说明符
but if I remove public access specifier from this method
@Test
void testShouldVerifyLoginRequest() {
}
输出:java.lang.Exception:方法testShouldVerifyLoginRequest()应该是公共的
Output: java.lang.Exception: Method testShouldVerifyLoginRequest() should be public
如此
-
幕后发生了什么?
What is happening behind the scenes?
是使用反射还是什么?
推荐答案
是的,测试运行程序正在幕后进行反射,以了解您的测试方法以及如何调用它们.
Yes, the test runner is using reflection behind the scenes to find out what your test methods are and how to call them.
如果方法不是public
,则调用它们可能会失败(因为SecurityManager否决了该方法).
If the methods were not public
, calling them might fail (because the SecurityManager gets to veto that).
这篇关于为什么Junit测试用例(方法)应该公开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!