build.xml
Didit builds projects using Ant.
As the author of a build configuration, security is your problem. Read build security for details.
Didit uses three Ant targets:
compile
: compile student and public test code.
Compilation success or failure plus console output is reported to students.
public
: run public tests.
Public test results and output are reported to students.
hidden
: compile and run hidden tests.
Hidden test results only are reported to students if and when they are released in a grade report.
The discussion below is for Java and JUnit, but any build testing process that generates results in the Ant JUnit XML format will work. Unfortunately, this XML format is not a documented standard.
compile
To ensure consistent compilation:
Didit provides eclipse.home
so student repos do not have to contain materials already distributed with Eclipse.
You can require eclipse.home
when staff run the build manually:
Find JUnit:
Then compile against JUnit by using refid="eclipse.junit.jar"
in the classpath.
Make sure compilation destination directories are removed (e.g. in a clean
target) and created by the compilation, e.g.:
Compilation usually takes place in two steps. For example:
Delay hidden test compilation. Since compilation output is reported to students, you may want to delay compilation of the hidden tests.
Compile against dummy versions. In some situations, “empty” versions of the student or staff code may be useful. For example, compile an “empty” implementation of the assignment with the correct method signatures but no code; then compile student-written tests against that empty implementation. Compilation will succeed only if the student is testing against the required specs. In the test targets, those tests can run against staff-provided implementations.
public
and hidden
testsSince security is your problem, you will want to read the documentation on build security:
TEST*.xml
.Here’s an outline of what the public
and hidden
targets might look like:
In most cases, you want to run Ant JUnit tasks with fork="yes"
so a separate process is used for each test class.
JUnit cannot reliably enforce timeouts for badly-behaving code, but including a timeout is advisable.
E.g.:
You can select test classes individually with nested test
elements:
<test name="ps0.staff.TurtleTest"/>
Or multiple classes with batchtest
:
<batchtest>
<fileset dir="bin-tests" includes="ps0/staff/*Test.class"/>
</batchtest>
You want a JVM arguments line to enable the security manager:
<jvmarg line="-Djava.security.manager -Djava.security.policy=security.policy"/>
You can also provide a description of these tests to be included on result pages by assigning a value to didit.desc
:
<jvmarg value="-Ddidit.desc=Testing penup and pendown"/>
And you must set the test report formatter to write XML files:
<formatter type="xml" usefile="true"/>
Each junit
task will generate a TEST-packagename.ClassName.xml
file.
Finally, after all of their junit
tasks, both public
and hidden
should generate a summary report called TESTS-TestSuites.xml
with all the test results:
You can generate test results with arbitrary payloads – text or binary data – that are accessible from build result pages on the web.
Assuming hello.png.gz.b64
is a base64-encoded gzipped PNG:
This example generates a ‘fake’ test result file with a single passing test that will link to hello.png
.
You can also deliver payloads attached to ‘real’ tests.
In build.xml
:
And in XSLT stylesheet payloads.xslt
:
This example adds hello.png
as the payload for test testHelloImage
.
You can run arbitrary tests using Ant tasks and include them in the test results and grade reports by generating XML result files by hand.
Use the echoxml
Ant task.
For an example, see generating payload-only tests above.