2

私はここの初心者です。

私の質問は、これらのクラスを 1 つの Java クラスで実行することは可能ですか?

@RunWith(Suite.class)
@Suite.SuiteClasses({
   Test.class,
   Chart.class,
})

注:
Test.class-> これはJunit テスト クラス
Chart.classです -> これはJava アプリケーション クラスです

私の質問が明確であることを願っています。私は英語がまったく得意ではありません。

このコードは Java アプリケーション用です: Chart.Class

public static class PieChart extends JFrame {


        private static final long serialVersionUID = 1L;

        public PieChart(String applicationTitle, String chartTitle) {
            super(applicationTitle);
            // This will create the dataset 
            PieDataset dataset = createDataset();
            // based on the dataset we create the chart
            JFreeChart chart = createChart(dataset, chartTitle);
            // we put the chart into a panel
            ChartPanel chartPanel = new ChartPanel(chart);
            // default size
            chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
            // add it to our application
            setContentPane(chartPanel);
            // it will save the chart on the specified location
            String fileLocation = "C:/temp/pieChartReport.jpg";
            saveChart(chart, fileLocation);   

        }

        /**
         * Creates a sample dataset 
         */
        ABMTLinks abmt = new ABMTLinks();


        private  PieDataset createDataset() {
            DefaultPieDataset result = new DefaultPieDataset();
            result.setValue("Failed:", abmt.Fail);
            result.setValue("Error:", 100);
            result.setValue("Passed:", abmt.Pass);
            return result;


        }

        /**
         * Creates a chart
         */

        private JFreeChart createChart(PieDataset dataset, String title) {

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

            PiePlot3D plot = (PiePlot3D) chart.getPlot();
            plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} {1} {2}")); //Shows the total count and percentage for Failed/Passed/Error
            plot.setStartAngle(480);
            plot.setDirection(Rotation.CLOCKWISE);
            plot.setForegroundAlpha(0.5f);
            return chart;

        }

        //This will store the chart on the specified location/folder
        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, 500, 270);
            } catch (IOException e) {
                e.printStackTrace();
                System.err.println("Problem occurred creating chart.");
            }
        }



        public static void main(String[] args) {
            String pieChartTitle = "Harold's Pie Chart";
            String pieChartName = "Pie Chart";
            PieChart demo = new PieChart(pieChartName, pieChartTitle);
            demo.pack();
            demo.setVisible(true);

            } 

    }

このコードは JUnit テスト コード用です: Test.Class

import com.thoughtworks.selenium.*;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;


public class ABMTLinks extends SeleneseTestCase {

      public int Fail=10, Pass=10;
      public static String
       //Declaring of variables to store the Actual values for URLs
         HMT = "http://dev.abmt.igloo.com.au/GetInvolved/Hostamorningtea/tabid/165/Default.aspx",
         DMT = "http://dev.abmt.igloo.com.au/GetInvolved/Donatetoamorningtea/tabid/141/Default.aspx";   

    @Before
    public void setUp() throws Exception {
        selenium = new DefaultSelenium("localhost", 1111, "*googlechrome", "http://dev.abmt.igloo.com.au/");
        selenium.start();
    }

    @Test
    public void testUntitled() throws Exception {
        selenium.open("/GetInvolved/tabid/114/Default.aspx");
        selenium.click("link=Get Involved");
        selenium.waitForPageToLoad("30000");

        if (URL.equals(HMT)
            && URL1.equals(DMT)
            ){

            Pass = Pass + 1;
            System.out.println("All pages redirects to each URL with no errors");           
        }
        else {
            Fail = Fail + 1;
            assertTrue("Test Case is Failed!", false);
            System.out.print("Failed");     
        }           
    }

    @After
    public void tearDown() throws Exception {   
        System.out.println(Fail + "+" + Pass);
    }   

}
4

2 に答える 2

2

いいえ、できません。

以下にリストされ@Suite.SuiteClasses({})ているクラスは、有効な Junit4 テスト クラスである必要があります。これらは、 で注釈が付けられた少なくとも 1 つのメソッドを持つクラスです@Test

于 2012-07-17T11:17:16.137 に答える
0

テスト結果を取得し、それに基づいて特別なレポートを生成しようとしているだけのように思えます。JUnit によって生成されたテスト レポートを読み取り、必要なグラフを作成する小さなプログラムを単純に作成してみませんか?


(追加) あなたがやっていることは間違った方向に向かっており、意味をなさないと私は信じていますが、おそらくあなたが調べることができる何かがあるでしょう.

Chart を呼び出して、Test の情報に基づいて円グラフを生成したいとおっしゃいましたが、@AfterClass の使用を検討できます。

public class Test {
  private int success;
  private int fail;


  @AfterClass
  public void generateChart() {
    // generate your chart base on this.success and this.fail
  }
}

@AfterClass は、このクラスのすべてのテストが呼び出された後に呼び出されます。

しかし、ユニットテストの全体的な考え方は、検証などをすべて自動的に行うことであり、プロセスやテストの結果を手動で検査するべきではないため、そうすることはまったく意味がありません。チャートを生成しても、コンピューターに成功/失敗を伝えるのには何の役にも立ちません。そして、あなたのコードが私に示唆しているのは、成功した/失敗したテストケースの数を示す通常の単体テストレポートにすぎません。真の価値のない余分なことをするのはなぜですか?

于 2012-07-18T02:28:38.343 に答える