问题描述
正在测试的类MyClass.javaJUnit测试用例名称的替代方案:
Class under test MyClass.javaJUnit test case name alternatives:
TestMyClass.java
MyClassTest.java
http://moreunit.sourceforge.net 似乎使用"Test"作为前缀默认值,但我已经看到两种用途.在Eclipse中将整个项目作为单元测试运行时,似乎两者都可以识别,因为这是为@Test解析的类中的注释.我猜maven会做同样的事情.
http://moreunit.sourceforge.net seems to use "Test" as prefix default but I have seen both uses. Both seems to be recognized when running the entire project as unit test in eclipse as it is the annotation inside classes that are parsed for @Test. I guess maven does the same thing.
哪个是首选?
推荐答案
后缀的另一个参数-至少在英语中:
Another argument for suffix - at least in english language:
一个类通常代表一个名词,它是一个概念的模型.您的测试之一的实例将是"MyClass测试".相反,一种方法可以对某种行为建模,例如测试[计算] [方法]".
A class usually represents a noun, it is a model of a concept. An instance of one of your tests would be a 'MyClass test'. In contrast, a method would model some kind of action, like 'test [the] calculate [method]'.
因此,我总是将'suffix'用于测试类,并将前缀用于测试方法:
Because of this, I'd always use the 'suffix' for test classes and the prefix for test methods:
the MyClass test --> MyClassTest
test the calculate method --> testCalculate()
这篇关于命名约定JUnit后缀或前缀Test的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!