tags:

views:

555

answers:

6

What are the best practices for naming ant targets?

For exmaple, what would you expect the target "test" to run? All unit tests? All functional tests? Both?

What are the standard names used for running different types of tests (unit/functional/all)? Are there standards for target names to deploy software in J2SE? in J2EE?

My project uses ant for a java project with junit, Swing applications, and J2EE applications.

+1  A: 

I think this is completely a point of personal preference, but I would use

  • test - for unit tests
  • test-integration - for integration tests
  • dbtest - for database tests (if they are included in the above item)
  • test-all to run all of the above

Also I'm agnostic on using test or the plural form tests, I've probably done both on different projects.

matt b
+2  A: 

As long as they are understandable and consistent throughout your project(s) what you name them is up to you. Simple, short verbs are usually the norm, and targets should be broken up logically.

You can go the route that Matt B suggested, naming your test targets by type:

  • test-unit
  • test-functional
  • test-all

Or you can name by tool, if, for example, you have Junit, Selenium, and Webtest functional tests:

  • test-junit
  • test-selenium
  • test-webtest
  • test-all

If you use the description attribute for targets that you want to expose to anyone building the project, users can perform an ant -p to list available targets and pick which one they want. Helpful descriptions here are probably more important and more valuable to users than what the targets are actually named.

From the Ant Manual:

The optional description attribute can be used to provide a one-line description of this target, which is printed by the -projecthelp command-line option. Targets without such a description are deemed internal and will not be listed, unless either the -verbose or -debug option is used.

Rob Hruska
+1  A: 

Your naming convention for ant targets should be very similar to the naming convention for Java methods: namely, simple and descriptive of what the target does.

Here's an excerpt from the Sun standard for method naming:

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

Probably the biggest difference is the style for ant targets, which should be all lower cased letters with words separated by dashes.

For example, the following targets seem appropriate to me:

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

In the end, try to use the same good judgment you use when naming methods. If your targets are clear, descriptive, and easy to understand, you are in good shape.

For more detailed information on the topic, check out The Elements of Ant Style on the Ant wiki.

Justin Standard
+1  A: 

We've made good experiences with short and concise target names that use a depend on other single tasks. AFAIK the general standard set is

  • init
  • clean
  • compile
  • dist
  • test
  • report

(can't find the link, though)

which works very well for us.

When we had to differentiate test-types, we named them "test.data" and "test.nondata" to separate the test types, each of them taken as a depend by the "test" task. Maybe you should use the "java method naming convention" as another user suggested, but IMHO that doesn't matter.

If you're running the ant script manually on your local machine (which I do to test if I have broken the build script) it comes in handy if you only have to type

ant dist
ant test report

instead of

ant compile create.distribution
ant test.data test.nondata report.junit.generate report .....
dhiller
+1  A: 

There is one standard that is reasonably widely used. Any target name beginning with the - character cannot be invoked from the command line, and as such must certainly be one that is not intended to be executed directly. Sometimes, this is referred to as a hidden target.

Bill Michell
+2  A: 

For my java projects I use the names defined in the maven default lifecycle as basis. For other projects I also have used the GNU autoconf standard targets.

Ludwig Weinzierl