Ant manages automated test scripts (1)

Source: Internet
Author: User

After learning about automated testing, we found that there are still many tools that can be used to manage test scripts and submit test efficiency. Whether Jenkins or ant.

I am currently learning ant. I personally feel that ant management scripts are simple and convenient. There is no operation interface, which is complicated for beginners.

Because of this, learners can gain a deep understanding of ant's working principles and configuration methods.

Ant uses XML files to manage scripts. The default file is build. xml.

Build. xml contains a multi-level definition of a unique project (project element ). Each project can define many targets (target elements), which can be dependent on each other. When executing such goals, you need to execute the goals they depend on.

 

Multiple tasks can be defined in each target, and the task sequence to be executed is also defined in the target. Ant must call the defined task when building the target. The task defines the commands actually executed by ant. The task in ant can be of three types.

 

(1) core tasks. The core task is the task that comes with ant.

 

(2) Optional tasks. Optional tasks come from third-party tasks. Therefore, an additional JAR file is required.

 

(3) custom tasks. A task developed by a user-defined task utility.

 

1. <project> label

 

Each build file corresponds to a project. <Project> Create the root tag of the file during tag creation. It can have multiple internal attributes, as shown in the Code. The meanings of each attribute are as follows.

 

(1) default indicates the default running target. This attribute is required.

 

(2) basedir indicates the baseline directory of the project.

 

(3) name indicates the project name.

 

(4) description indicates the description of the project.

 

Each build file corresponds to a project, but a large project often contains a large number of sub-projects. Each sub-project can have its own build file.

 

2. <target> tag

 

A project tag can contain one or more target tags. A target tag can depend on other target tags.

 

For example, one target is used to compile the program, and the other target is used to claim executable files. Compile the file before generating an executable file, because the target of the executable file depends on the target of the Compilation Program. All properties of target are as follows.

 

(1). name indicates that this attribute is required.

 

(2). Depends indicates the target of the dependency.

 

(3) If indicates that it is executed only when the attribute is set.

 

(4) unless: it is executed only when the property is not set.

 

(5) description indicates the description of the project.

 

The depends attribute of ant specifies the execution sequence of the target. Ant will execute each target in sequence according to the Appearance Order of the target in the depends attribute. Before execution, you must first execute the target on which it depends. In the program, the depends attribute of target named run is compile, And the depends attribute of target named compile is prepare. Therefore, the execution sequence of these targets is prepare-> compile-> Run.

 

A target can only be executed once, even if multiple targets depend on it. If there is no if or unless attribute, the target will always be executed.

 

3. <mkdir> label

 

This label is used to create a directory. It has the Dir attribute to specify the name of the Created directory. The Code is as follows:

 

<Mkdir dir = "$ {class. Root}"/>

 

The code above creates a directory that has been specified by the previous property tag.

 

4 <jar> labels

 

This label is used to generate a jar file. Its Attributes are as follows.

 

(1) destfile indicates the JAR file name.

 

(2) basedir indicates the file name to be archived.

 

(3) des indicates the file mode for non-archiving.

 

(4) exchudes indicates the excluded file mode.

 

5. <javac tag>

 

This label is used to compile one or more java files. Its Attributes are as follows.

 

(1). srcdir indicates the directory of the source program.

 

(2). destdir indicates the output directory of the class file.

 

(3). Include indicates the mode of the compiled file.

 

(4). Excludes indicates the mode of excluded files.

 

(5). classpath indicates the class path used.

 

(6). debug indicates the debugging information contained.

 

(7). Optimize indicates whether to use optimization.

 

(8). verbose indicates providing detailed output information.

 

(9). fileonerror indicates that it is automatically stopped when an error occurs.

 

6. <Java> labels

 

This label is used to execute the compiled. Class file. Its Attributes are as follows.

 

(1). classname indicates the name of the class to be executed.

 

(2). jar indicates the JAR file name containing the class.

 

(3). classpath indicates the class path used.

 

(4). Fork indicates that the class is run in a new virtual machine.

 

(5). failonerror indicates automatic stop when an error occurs.

 

(6). Output indicates the output file.

 

(7). append indicates appending or overwriting the default file.

 

7. <Delete> tag

 

This label is used to delete a file or a group of files. Its Attributes are as follows.

 

(1)/file indicates the file to be deleted.

 

(2). dir indicates the directory to be deleted.

 

(3). includeemptydirs indicates whether to delete an empty directory. The default value is Delete.

 

(4). failonerror indicates whether to stop an error. The default value is automatic stop.

 

(5). verbose indicates whether to list the deleted files. The default value is not listed.

 

8. <copy> label

 

This label is used to copy a file or file set. Its Attributes are as follows.

 

(1). file indicates the source file.

 

(2). tofile indicates the target file.

 

(3). todir indicates the target directory.

 

(4) overwrite indicates whether to overwrite the target file. The default value is not overwrite.

 

(5). includeemptydirs indicates whether to copy an empty directory. The default value is copy.

 

(6). failonerror indicates whether to stop automatically if the target is not found. The default value is stop.

 

(7). verbose indicates whether to display details. The default value is not.

Ant manages automated test scripts (1)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.