Table of Contents

Configuring unit tests in Ant projects


Prerequisites

Ant project is opened in Visual Studio. You can find instructions how to create an Ant project in this section. The project contains some testable code as well as targets to compile and pack the code. This section shows how to manage targets. This section shows how to manage tasks within a target.

This section shows how to configure JUnit tests in Ant project, using the standard JUnit task provided by Ant. Ant supports JUnit 3.x and 4.x. Before using it, you need to copy junit.jar into the $ANT_HOME/lib directory. For JUnit 4.x you also will likely need to copy hamcrest-core-xx.jar (where xx is some version number) into that directory as well. Please consult Ant and JUnit docs for detailed description of requirements. For JUnit 4.11, Hamcrest 1.3 version seems appropriate.

In case of missing JUnit or Hamcrest, your tests will fail.

Actions

In order to configure unit testing in your project, do the following:

After those preparations, relevant Solution Explorer nodes will look like this:

Now, the final (and most important) part is to write the testing code itself. You will use APIs and annotations provided by JUnit. Please refer to JUnit docs for the details. Make sure that your testing classes names matches the ones entered for Test targets. A basic example of testing code might look like this:

Table of Contents


Copyright (C) 2014-2016 SOFT-ERG. All rights reserved.