Djunit---------Ant 执行指南

我想大家一定会遇到这个问题的

Djunit 是很强大的软件,主要是日企使用,具体的说明请看下面的官网:

http://works.dgic.co.jp/djunit/

Ant 也是一个很强大的软件,是构建工具,现在也不比较流行。具体的在下面官网

http://ant.apache.org/

现在就给大家说明下他们的组合使用:

为什么要组合使用那。。。

我想大家要是看到这篇文章的话一定是遇到问题了。。。

现在我就写了一个简单的sample,大家看了就会明白的

主要是用到的jar包

asm-2.2.1.jar

asm-attrs-1.5.3.jar

djunit.jar

jakarta-oro-2.0.7.jar

jcoverage-djunit-1.0.5.jar

junit.jar

一下是sample代码:

 

package com.chenhailong.source;

/**
 * 
 * @author chenhailong
 * 
 */
public class Simple {

    private String name;
    private boolean sex;
    private int age;
    private String localtion;
    private String company;

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @param name
     *            the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @return the sex
     */
    public boolean isSex() {
        return sex;
    }

    /**
     * @param sex
     *            the sex to set
     */
    public void setSex(boolean sex) {
        this.sex = sex;
    }

    /**
     * @return the age
     */
    public int getAge() {
        return age;
    }

    /**
     * @param age
     *            the age to set
     */
    public void setAge(int age) {
        this.age = age;
    }

    /**
     * @return the localtion
     */
    public String getLocaltion() {
        return localtion;
    }

    /**
     * @param localtion
     *            the localtion to set
     */
    public void setLocaltion(String localtion) {
        this.localtion = localtion;
    }

    /**
     * @return the company
     */
    public String getCompany() {
        return company;
    }

    /**
     * @param company
     *            the company to set
     */
    public void setCompany(String company) {
        this.company = company;
    }

    public Simple getMember() {
        Simple simple = new Simple();
        simple.age = 10;
        simple.company = "dnc.2010";
        simple.localtion = "shenyang";
        simple.name = "zhangli";
        simple.sex = true;
        return simple;
    }

}

 

Test 代码

package com.chenhailong.test;

import jp.co.dgic.testing.framework.DJUnitTestCase;

import com.chenhailong.source.Simple;


/**
 * 
 * @author chenhailong
 *
 */
public class SimpleTest extends DJUnitTestCase{

    @Override
    protected void setUp() throws Exception {
        super.setUp();
    }

    public void testGetMember() {
        Simple simple = new Simple();
        simple.setAge(10);
        simple.setCompany("dnc");
        simple.setLocaltion("shanghai");
        simple.setName("chenhailong");
        simple.setSex(false);
        addReturnValue(Simple.class, "getMember", simple);
        simple = simple.getMember();
        assertEquals("dnc", simple.getCompany());
        assertEquals("shanghai", simple.getLocaltion());
        assertEquals("chenhailong", simple.getName());
        assertEquals(10, simple.getAge());
        assertEquals(false, simple.isSex());
    }

}

 build.properties

djunit.lib.dir=E:/JavaPortlet/Djunit/lib
junit.report.dir=./report/junit
coverage.report.dir=./report/coverage

 build.xml

<?xml version="1.0" encoding="Windows-31J"?>

<project name="djUnit" basedir="." default="djunit.report">

	<taskdef resource="djunittasks.properties" classpath="./lib/djunit.jar" />

	<property file="build.properties" />

	<path id="class.path">
		<fileset dir="${djunit.lib.dir}">
			<include name="**/*.jar" />
		</fileset>
	</path>
	<!--=============== compile ===============-->
	<target name="compile">
		<mkdir dir="./classes" />
		<javac srcdir="./src" destdir="./bin" debug="yes" includeantruntime="false" />
		<copy todir="./classes">
			<fileset dir="./bin">
				<include name="**/*.class"/>
			</fileset>
		</copy>
	</target>
	<!--=============== test ===============-->
	<target name="djunit.test" depends="compile">
		<delete dir="${junit.report.dir}" />
		<mkdir dir="${junit.report.dir}" />
		<djunit printsummary="yes" targetsrcdir="./src" virtualmock="yes" coverage="yes" asmversion="ASM2">
			<classpath refid="class.path" />
			<classpath path="./classes" />
			<formatter type="xml" />
			<batchtest todir="${junit.report.dir}">
				<fileset dir="./classes">
					<include name="**/*Test.class" />
				</fileset>
			</batchtest>
		</djunit>
		<junitreport>
			<fileset dir="${junit.report.dir}">
				<include name="TEST-*.xml" />
			</fileset>
			<report format="frames" todir="${junit.report.dir}" />
		</junitreport>
	</target>
	<!--=============== djUnit Coverage Report ===============-->
	<target name="djunit.report" depends="djunit.test">
		<delete dir="${coverage.report.dir}" />
		<mkdir dir="${coverage.report.dir}" />
		<djunit-coverage-report serFile="./jcoverage.ser" srcdir="./src" destdir="${coverage.report.dir}">
			<classpath refid="class.path" />
		</djunit-coverage-report>
	</target>
</project>

 执行的结果如下:

Buildfile: E:\JavaPortlet\Djunit\build.xml
compile:
djunit.test:
   [delete] Deleting directory E:\JavaPortlet\Djunit\report\junit
    [mkdir] Created dir: E:\JavaPortlet\Djunit\report\junit
   [djunit] Running com.chenhailong.test.SimpleTest
   [djunit] Running com.chenhailong.test.SimpleTest
   [djunit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.64 sec
[junitreport] Processing E:\JavaPortlet\Djunit\TESTS-TestSuites.xml to C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\null1445352326
[junitreport] Loading stylesheet jar:file:/E:/eclipseTPTP/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant-junit.jar!/org/apache/tools/ant/taskdefs/optional/junit/xsl/junit-frames.xsl
[junitreport] Transform time: 1047ms
[junitreport] Deleting: C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\null1445352326
djunit.report:
   [delete] Deleting directory E:\JavaPortlet\Djunit\report\coverage
    [mkdir] Created dir: E:\JavaPortlet\Djunit\report\coverage
[djunit-coverage-report] djUnit coverage report
BUILD SUCCESSFUL
Total time: 4 seconds

 现在大家就尝试一下

heihei 在完善一下:

@echo off

echo batTest ant

call ant -version
 pause

<?xml version="1.0" ?>
<project basedir="." default="echo" name="chenhailong">

	<target name="echo">
		<echo message="hello chenhailong" />
	</target>
	<target name="test">
		<echo message="My cock is big" />
	</target>
</project>

 

如果有什么问题请和我联系

还有就是 如果要转载的话请注明作者和地址 谢谢

 

你可能感兴趣的:(apache,xml,ant,JUnit,XSL)