英文:
Is there some reason to make TestNG @Test annotated methods public versus private?
问题
@Test注释的方法是public还是private是否有一些原因?我想要保持一致,但不确定该使用哪个。
@Test
private void testMyStuff() {}
或者
@Test
public void testMyStuff() {}
或其他?
英文:
Is there some reason to make TestNG @Test annotated methods public versus private?
I want to be consistent but not sure which one to use.
@Test
private void testMyStuff() {}
or
@Test
public void testMyStuff() {}
or other?
答案1
得分: 1
我不是专家,特别是在处理TestNG方面,但我经常用Java编写单元测试。
我建议从测试方法中完全删除可见性关键字,以提高可读性(将它们设置为包私有或默认可见)。
@Test
void testMyStuff() {}
如果TestNG允许这样做,它只会减少你需要阅读以理解代码的字符数量。可见性对于测试方法所需的信息没有任何有用的添加。这样还可以节省输入时间。
英文:
I am not an expert especially with TestNG but regularly write unit tests in Java.
I recommend to remove the visibility keyword completely from the test methods for improved readability (making them package private or default visible).
@Test
void testMyStuff() {}
If TestNG allows for this, it simply will reduce the number of characters you visually have to read to understand the code. The visibility does not add anything useful to the information you need for a test method. You also will save time typing it.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论