亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

JUnit 執行所有包的所有測試類

JUnit 執行所有包的所有測試類

慕的地6264312 2022-07-06 19:01:32
有什么方法可以一次構建 JUnit 的所有測試用例?就像在“Ruby on rails”上通過命令“rake test”執行所有測試類。對于 Java,我看到了一些在包中執行所有測試的解決方案。但我想為所有包執行所有測試用例??赡軉幔课覒撊绾翁幚?build.xml 文件?
查看完整描述

2 回答

?
料青山看我應如是

TA貢獻1772條經驗 獲得超8個贊

您可以運行按包名或類名過濾的所有測試或特定測試。這是<batchtest>取自JUnit 任務手冊的示例:


<junit printsummary="yes" haltonfailure="yes">

    <classpath>

        <pathelement location="${build.tests}"/>

        <pathelement path="${java.class.path}"/>

    </classpath>


    <formatter type="plain"/>


    <test name="my.test.TestCase" haltonfailure="no" outfile="result">

        <formatter type="xml"/>

    </test>


    <batchtest fork="yes" todir="${reports.tests}">

        <fileset dir="${src.tests}">

            <include name="**/*Test*.java"/>

            <exclude name="**/AllTests.java"/>

        </fileset>

    </batchtest>

</junit>

您可以根據需要調整<include name=""/>/<exclude name=""/>元素或添加更多包含/排除元素。<target/>然后,您可以為不同的測試創建不同的 ant <target name="all-tests"/>,例如<target name="package-foo-tests"/>等。


查看完整回答
反對 回復 2022-07-06
?
ibeautiful

TA貢獻1993條經驗 獲得超6個贊

我還不能添加評論,這就是我發布這個答案的原因。


我認為您需要的是一個測試套件類。


如下所示。


package com.emeter.test.predeploy.sdm.common;


import org.junit.runner.RunWith;

import org.junit.runners.Suite;

import org.junit.runners.Suite.SuiteClasses;


import com.emeter.test.predeploy.sdm.svc.TestOutdatedComponentRpt;

import com.emeter.test.predeploy.sdm.svc.TestSubstationSvc;

import com.emeter.test.predeploy.sdm.svc.TestSvmComponentSvc;

import com.emeter.test.predeploy.sdm.svc.TestSvmNotificationSvc;


@RunWith(Suite.class)

@SuiteClasses({


TestSubstationSvc.class,

TestSvmComponentSvc.class,

TestSvmNotificationSvc.class,

TestOutdatedComponentRpt.class

 }

)

public class TestSuite {


}

您可以從任何包中導入所需的類,然后一次運行它們。包含測試用例的類放在“SuiteClasses”注釋下。


編輯:您只需像 eclipse 中的任何其他測試用例文件一樣運行它。


查看完整回答
反對 回復 2022-07-06
  • 2 回答
  • 0 關注
  • 252 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號