@Test注解的方法是公共的还是私有的,有什么特殊原因吗?

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

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.

huangapple
  • 本文由 发表于 2023年5月24日 21:37:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/76324163.html
匿名

发表评论

匿名网友

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

确定