起名ant目标的最佳实践是什么?

10

命名ant目标的最佳实践是什么?

例如,您希望目标“test”运行什么?所有单元测试?所有功能测试?还是两者兼有?

运行不同类型测试(单元/功能/全部)的标准名称是什么?在J2SE中部署软件的目标名称是否有标准?在J2EE中呢?

我的项目使用ant进行Java项目、JUnit、Swing应用程序和J2EE应用程序的构建。

7个回答

16

请参见此页面上的"命名约定"部分Ant风格要素

以下目标在许多构建中都很常见。始终避免更改已知目标名称的行为。您不需要在单个项目中实现所有这些目标。

all               Build and test everything; create a distribution, optionally install. 
clean             Delete all generated files and directories. 
deploy            Deploy the code, usually to a remote server. 
dist              Produce the distributables. 
distclean         Clean up the distribution files only. 
docs              Generate all documentation. 
init              Initialize the build: create directories, call <tstamp> and other common actions. 
install           Perform a local installation. 
javadocs          Generate the Javadoc pages. 
printerdocs       Generate printable documents. 
test              Run the unit tests. 
uninstall         Remove a local installation. 

这个页面还提供了其他好的指南。


6

3

有一个相当广泛使用的标准。任何以“-”字符开头的目标名称都不能从命令行调用,因此肯定是不打算直接执行的目标。有时,这被称为隐藏目标


2
只要它们在整个项目中是可理解的并且保持一致,你可以自己决定它们的命名。通常情况下,简单、短小的动词是常规用法,目标应该被逻辑地分解。
你可以按照Matt B的建议,按类型命名测试目标:
- test-unit - test-functional - test-all
或者按工具命名,例如你有Junit、Selenium和Webtest功能测试:
- test-junit - test-selenium - test-webtest - test-all
如果你使用描述属性来公开项目构建过程中需要的目标,用户可以执行“ant -p”列出可用目标并选择他们想要的目标。这里有帮助的描述可能比目标的实际名称更重要,对用户更有价值。
来自Ant手册
可选的描述属性可以用来提供这个目标的一行描述,该描述将被-printed by the -projecthelp命令行选项。没有这样描述的目标被视为内部目标,并且不会列出,除非使用-verbose或-debug选项。

2
我们发现,使用简短而简洁的目标名称,并且这些名称依赖于其他单个任务,效果很好。据我所知,通用的标准集如下:
  • init
  • clean
  • compile
  • dist
  • test
  • report
(虽然找不到链接)
对我们来说,这非常有效。
当我们需要区分测试类型时,我们将它们命名为“test.data”和“test.nondata”,以区分测试类型,每个测试类型都作为“test”任务的依赖项。也许你应该使用“Java方法命名约定”,正如另一个用户建议的那样,但在我看来,这并不重要。
如果你手动在本地机器上运行ant脚本(这是我用来测试是否已破坏构建脚本的方法),那么只需键入以下内容即可:
ant dist
ant test report

替代

ant compile create.distribution
ant test.data test.nondata report.junit.generate report .....

1

我认为这完全是个人喜好的问题,但我会使用以下命名:

  • test - 用于单元测试
  • test-integration - 用于集成测试
  • dbtest - 用于数据库测试(如果它们包含在上述项目中)
  • test-all - 运行以上所有测试

此外,我对使用test或复数形式tests持中立态度,我可能在不同的项目中都使用过。


1

你的ant targets命名约定应该非常类似于Java方法的命名约定:即简单并描述目标所执行的操作。

以下是Sun method 命名标准的摘要:

Naming a Method

Although a method name can be any legal identifier, code conventions restrict method names. By convention, method names should be a verb in lowercase or a multi-word name that begins with a verb in lowercase, followed by adjectives, nouns, etc. In multi-word names, the first letter of each of the second and following words should be capitalized. Here are some examples:

run
runFast
getBackground
getFinalData
compareTo
setX
isEmpty

可能最大的区别在于Ant目标的风格,应该全部使用小写字母,并用破折号分隔单词。

例如,以下目标对我来说似乎是合适的:

  • run-all-tests
  • build
  • clean
  • test-and-release
  • deploy
  • run-code-coverage-metrics

最后,请尽量使用与命名方法相同的良好判断力。如果您的目标清晰、描述明确且易于理解,则处于良好状态。

有关此主题的更详细信息,请查看Ant wiki上的Ant Style元素


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接