Java 任何可运行的方法和测试类都不应该只有一个公共零参数构造函数

Java 任何可运行的方法和测试类都不应该只有一个公共零参数构造函数,java,ant,selenium,junit,Java,Ant,Selenium,Junit,每当我在Ant中运行我的代码时,我都会遇到一个错误,但是在eclipse上使用(run>junitest),它运行得很好,没有错误 <classpath refid="Igloo.path" /> <batchtest todir="${Igloo.reportsDir}" fork="true"> <fileset dir="${Igloo.dest}">

每当我在Ant中运行我的代码时,我都会遇到一个错误,但是在eclipse上使用(run>junitest),它运行得很好,没有错误

                <classpath refid="Igloo.path" />
                <batchtest todir="${Igloo.reportsDir}" fork="true">
                    <fileset dir="${Igloo.dest}">
                        <include name="ABMTLinks.class" />
                        <exclude name = "PieChart.class" />
                        <exclude name = "PieChart.java" />
                    </fileset>
                </batchtest>
            <formatter type="xml" />
            <classpath refid="Igloo.path" />
            </junit>

                <junitreport todir="${Igloo.reportsDir}">
                    <fileset dir="${Igloo.reportsDir}">
                        <include name="TEST-*.xml" />
                    </fileset>
                    <report todir="${Igloo.reportsDir}"/>       
                </junitreport>
        </target>
下面是我生成报告时收到的错误消息:

                <classpath refid="Igloo.path" />
                <batchtest todir="${Igloo.reportsDir}" fork="true">
                    <fileset dir="${Igloo.dest}">
                        <include name="ABMTLinks.class" />
                        <exclude name = "PieChart.class" />
                        <exclude name = "PieChart.java" />
                    </fileset>
                </batchtest>
            <formatter type="xml" />
            <classpath refid="Igloo.path" />
            </junit>

                <junitreport todir="${Igloo.reportsDir}">
                    <fileset dir="${Igloo.reportsDir}">
                        <include name="TEST-*.xml" />
                    </fileset>
                    <report todir="${Igloo.reportsDir}"/>       
                </junitreport>
        </target>
“测试类应该只有一个公共零参数构造函数”

                <classpath refid="Igloo.path" />
                <batchtest todir="${Igloo.reportsDir}" fork="true">
                    <fileset dir="${Igloo.dest}">
                        <include name="ABMTLinks.class" />
                        <exclude name = "PieChart.class" />
                        <exclude name = "PieChart.java" />
                    </fileset>
                </batchtest>
            <formatter type="xml" />
            <classpath refid="Igloo.path" />
            </junit>

                <junitreport todir="${Igloo.reportsDir}">
                    <fileset dir="${Igloo.reportsDir}">
                        <include name="TEST-*.xml" />
                    </fileset>
                    <report todir="${Igloo.reportsDir}"/>       
                </junitreport>
        </target>
异常:测试类应该只有一个公共 零参数构造函数 java.lang.reflect.Constructor.newInstance(未知源)

                <classpath refid="Igloo.path" />
                <batchtest todir="${Igloo.reportsDir}" fork="true">
                    <fileset dir="${Igloo.dest}">
                        <include name="ABMTLinks.class" />
                        <exclude name = "PieChart.class" />
                        <exclude name = "PieChart.java" />
                    </fileset>
                </batchtest>
            <formatter type="xml" />
            <classpath refid="Igloo.path" />
            </junit>

                <junitreport todir="${Igloo.reportsDir}">
                    <fileset dir="${Igloo.reportsDir}">
                        <include name="TEST-*.xml" />
                    </fileset>
                    <report todir="${Igloo.reportsDir}"/>       
                </junitreport>
        </target>
“没有可运行的方法” -java.lang.Exception:java.lang.reflect.Constructor.newInstance处没有可运行的方法(未知源)

                <classpath refid="Igloo.path" />
                <batchtest todir="${Igloo.reportsDir}" fork="true">
                    <fileset dir="${Igloo.dest}">
                        <include name="ABMTLinks.class" />
                        <exclude name = "PieChart.class" />
                        <exclude name = "PieChart.java" />
                    </fileset>
                </batchtest>
            <formatter type="xml" />
            <classpath refid="Igloo.path" />
            </junit>

                <junitreport todir="${Igloo.reportsDir}">
                    <fileset dir="${Igloo.reportsDir}">
                        <include name="TEST-*.xml" />
                    </fileset>
                    <report todir="${Igloo.reportsDir}"/>       
                </junitreport>
        </target>
请查看我的代码:

                <classpath refid="Igloo.path" />
                <batchtest todir="${Igloo.reportsDir}" fork="true">
                    <fileset dir="${Igloo.dest}">
                        <include name="ABMTLinks.class" />
                        <exclude name = "PieChart.class" />
                        <exclude name = "PieChart.java" />
                    </fileset>
                </batchtest>
            <formatter type="xml" />
            <classpath refid="Igloo.path" />
            </junit>

                <junitreport todir="${Igloo.reportsDir}">
                    <fileset dir="${Igloo.reportsDir}">
                        <include name="TEST-*.xml" />
                    </fileset>
                    <report todir="${Igloo.reportsDir}"/>       
                </junitreport>
        </target>
此代码有注释(@)

                <classpath refid="Igloo.path" />
                <batchtest todir="${Igloo.reportsDir}" fork="true">
                    <fileset dir="${Igloo.dest}">
                        <include name="ABMTLinks.class" />
                        <exclude name = "PieChart.class" />
                        <exclude name = "PieChart.java" />
                    </fileset>
                </batchtest>
            <formatter type="xml" />
            <classpath refid="Igloo.path" />
            </junit>

                <junitreport todir="${Igloo.reportsDir}">
                    <fileset dir="${Igloo.reportsDir}">
                        <include name="TEST-*.xml" />
                    </fileset>
                    <report todir="${Igloo.reportsDir}"/>       
                </junitreport>
        </target>
此代码在上述代码中继承,用于生成饼图并将其保存在文件夹中

import java.awt.Color;
import java.awt.Font;
import java.io.File;
import java.io.IOException;    
import javax.swing.JFrame;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.labels.StandardPieSectionLabelGenerator;
import org.jfree.chart.plot.PiePlot;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.general.PieDataset;

public class PieChart extends JFrame {

    public static final long serialVersionUID = 1L;

    public PieChart(int iPass, int iFail, int iError, String applicationTitle, String chartTitle, int iLeft, int iRight, String sPath) {
        super(applicationTitle);
        PieDataset dataset = createDataset(iFail, iError, iPass);
        JFreeChart chart = createChart(dataset, chartTitle);
        ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize(new java.awt.Dimension(iLeft, iRight));
        setContentPane(chartPanel);
        String fileLocation =  sPath ;
        saveChart(chart, fileLocation);   

    }

    /**
     * Creates a sample dataset 
     */
    public  PieDataset createDataset(int iFail, int iError, int iPass) {
        DefaultPieDataset result = new DefaultPieDataset();
        result.setValue("Failed:", iFail);
        result.setValue("Error:", iError);
        result.setValue("Passed:", iPass);
        return result;    
    }

    /**
     * Creates a chart
     */
    public JFreeChart createChart(PieDataset dataset, String title) {

        JFreeChart chart = ChartFactory.createPieChart(title,               // chart title
            dataset,                // data
            true,                   // include legend
            true,
            false);

        PiePlot plot = (PiePlot) chart.getPlot();
        plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));
        plot.setCircular(false);
        plot.setLabelGap(0.02);
        plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} {1} ({2})")); //Shows the total count and percentage for Failed/Passed/Error
        return chart;

    }
    public void saveChart(JFreeChart chart, String fileLocation) {
        String fileName = fileLocation;
        try {
            /**
             * This utility saves the JFreeChart as a JPEG First Parameter:
             * FileName Second Parameter: Chart To Save Third Parameter: Height
             * Of Picture Fourth Parameter: Width Of Picture
             */
            ChartUtilities.saveChartAsJPEG(new File(fileName), chart, 800, 600);
        } catch (IOException e) {
            e.printStackTrace();
            System.err.println("Problem occurred creating chart.");
        }
    }

}
                <classpath refid="Igloo.path" />
                <batchtest todir="${Igloo.reportsDir}" fork="true">
                    <fileset dir="${Igloo.dest}">
                        <include name="ABMTLinks.class" />
                        <exclude name = "PieChart.class" />
                        <exclude name = "PieChart.java" />
                    </fileset>
                </batchtest>
            <formatter type="xml" />
            <classpath refid="Igloo.path" />
            </junit>

                <junitreport todir="${Igloo.reportsDir}">
                    <fileset dir="${Igloo.reportsDir}">
                        <include name="TEST-*.xml" />
                    </fileset>
                    <report todir="${Igloo.reportsDir}"/>       
                </junitreport>
        </target>
下面是我的XML代码:

<?xml version="1.0" encoding="iso-8859-1"?>

<project name="JUnitTest1" default="usage" basedir=".">
    <!-- Create a folder with date and time -->
    <tstamp prefix="start">
        <format property="dateTime" pattern="MM-dd-YYYY HH-MM-ss" />
    </tstamp>

    <property environment = "env"/>
    <property name="ws.home" value="${basedir}"/>
    <property name="ws.jars" value="C:/Selenium/selenium-2.24.1"/>
    <property name="Igloo.dest" value="${ws.home}/build"/>
    <property name="Igloo.src" value="${ws.home}/src"/>
    <property name="Igloo.reportsDir" value="C:/reports/report ${start.dateTime}"/>
    <propert name="junit.style.dir" value = "C:/xsl/junit-frames.xsl" />

    <path id="Igloo.path">
        <pathelement location="${Igloo.dest}" />
        <fileset dir = "${ws.jars}" >
            <include name = "*.jar" />
        </fileset>
    </path>

    <target name="setClassPath" unless="Igloo.classpath">
        <path id="classpath_jars">
            <fileset dir="${ws.jars}" includes="*.jar" />
        </path>

        <pathconvert pathsep=": "
            property = "Igloo.classpath"
            refid = "classpath_jars"/>
    </target>

    <target name="init" depends="setClassPath">
        <tstamp>
            <format property="start.time" pattern="MM/dd/yyyy hh:mm ss" />
        </tstamp>

        <condition property="ANT"
            value = "${env.ANT_HOME}/bin/ant.bat"
            else = "${env.ANT_HOME}/bin/ant">
                <os family="windows" />
        </condition>
    </target>

    <!-- Clean -->
    <target name="clean">
        <delete dir="${Igloo.dest}"/>
    </target>

    <!-- Compile -->
    <target name="compile" depends="init, clean">
        <delete includeemptydirs="true" quiet="true">
            <fileset dir="${Igloo.dest}" includes="**/*"/>
        </delete>

        <echo message="making directory..."/>
        <mkdir dir="${Igloo.dest}" />
        <echo message="classpath ...: ${Igloo.classpath}"/>
        <echo message="compiling..."/>

        <javac
            debug="true"
            destdir="${Igloo.dest}"
            srcdir="${Igloo.src}"
            target="1.7"
            classpath="${Igloo.classpath}"
        >
        </javac>

    </target>

    <!-- build -->
    <target name="build" depends="init">
    </target>

    <target name="usage">
        <echo>
            ant run will execute the test
        </echo>
    </target>

    <!-- Run -->
    <target name="run">
        <mkdir dir="${Igloo.reportsDir}" />
        <delete includeemptydirs="true" quiet="true">
            <fileset dir="${Igloo.reportsDir}" includes="**/*" />       
        </delete>
        <java jar="${ws.jars}" fork="true" spawn="true" />
        <junit fork="yes" haltonfailure="no" printsummary="yes">

            <classpath refid="Igloo.path" />
            <batchtest todir="${Igloo.reportsDir}" fork="true">
                <fileset dir="${Igloo.dest}">
                    <include name="ABMTLinks.class" /> 
                </fileset>
            </batchtest>
        <formatter type="xml" />
        <classpath refid="Igloo.path" />
        </junit>

            <junitreport todir="${Igloo.reportsDir}">
                <fileset dir="${Igloo.reportsDir}">
                    <include name="TEST-*.xml" />
                </fileset>
                <report todir="${Igloo.reportsDir}"/>       
            </junitreport>
    </target>
</project>
                <classpath refid="Igloo.path" />
                <batchtest todir="${Igloo.reportsDir}" fork="true">
                    <fileset dir="${Igloo.dest}">
                        <include name="ABMTLinks.class" />
                        <exclude name = "PieChart.class" />
                        <exclude name = "PieChart.java" />
                    </fileset>
                </batchtest>
            <formatter type="xml" />
            <classpath refid="Igloo.path" />
            </junit>

                <junitreport todir="${Igloo.reportsDir}">
                    <fileset dir="${Igloo.reportsDir}">
                        <include name="TEST-*.xml" />
                    </fileset>
                    <report todir="${Igloo.reportsDir}"/>       
                </junitreport>
        </target>

ant run将执行测试
请帮忙。
我已经解决了我的问题,谢谢你的帮助。。我只是排除了PieChart.class,因为每当我运行junit时,因为PieChart.class是一个实用类,所以不能在ant中运行。。在xml上,我只是排除了类,
,只是为了确保添加了
                <classpath refid="Igloo.path" />
                <batchtest todir="${Igloo.reportsDir}" fork="true">
                    <fileset dir="${Igloo.dest}">
                        <include name="ABMTLinks.class" />
                        <exclude name = "PieChart.class" />
                        <exclude name = "PieChart.java" />
                    </fileset>
                </batchtest>
            <formatter type="xml" />
            <classpath refid="Igloo.path" />
            </junit>

                <junitreport todir="${Igloo.reportsDir}">
                    <fileset dir="${Igloo.reportsDir}">
                        <include name="TEST-*.xml" />
                    </fileset>
                    <report todir="${Igloo.reportsDir}"/>       
                </junitreport>
        </target>

                <classpath refid="Igloo.path" />
                <batchtest todir="${Igloo.reportsDir}" fork="true">
                    <fileset dir="${Igloo.dest}">
                        <include name="ABMTLinks.class" />
                        <exclude name = "PieChart.class" />
                        <exclude name = "PieChart.java" />
                    </fileset>
                </batchtest>
            <formatter type="xml" />
            <classpath refid="Igloo.path" />
            </junit>

                <junitreport todir="${Igloo.reportsDir}">
                    <fileset dir="${Igloo.reportsDir}">
                        <include name="TEST-*.xml" />
                    </fileset>
                    <report todir="${Igloo.reportsDir}"/>       
                </junitreport>
        </target>


ABMTSuite是什么样子的?这些代码来自selenium,我添加了一个条件,只是为了跟踪测试用例是否失败/通过,顺便说一句,忽略@test中的代码,我只是使用selenium记录,这只会出现在google站点上,然后键入一个搜索关键字,就这样。正如您所看到的,我强制在if-else条件下通过了这个测试——这只是一个测试,在这里它将调用PieChart.class来生成一个饼图,并将其保存到指定的位置。希望我能回答你的问题。对不起,我的英语不好。如果您执行ABMTSuite,请显示套件的代码。或者将ant改为使用ABMTLinks。我没有套件,在eclipse中我只运行代码ABMTLinks by(run>junittest)并工作。在ant上时,例如我的类文件夹:C:/workspace/ABMT Test/:然后我在命令提示符下键入ant命令。。e、 g C:/workspace/ABTM Test/:ant clean C:/workspace/ABTM Test/:ant compile C:/workspace/ABTM Test/:ant run如果您有套件,请查看ant文件中的junit任务!