ABAP和Java的單元測試Unit Test

來源:互聯網
上載者:User

標籤:stc   依次   mvn   efault   you   mave   指定   log   image   

ABAP

ABAP class單元測試的執行入口,CLASS_SETUP, 是寫入程式碼在單元測試架構實現CL_AUNIT_TEST_CLASS裡的。


待執行的單元測試方法通過CL_AUNIT_TEST_CLASS~get_Test_Methods返回到一個內表裡,然後LOOP該內表,依次執行。

Java

最常用的Maven plugin是maven-surefire-plugin,可以方便地單獨觸發單元測試,或者把單元測試的執行整合為Maven build的一個子步驟。


表明在執行mvn clean install時,執行了srv/test/java/com/sap/testcase下面的兩個test case:

那麼maven-surefire-plugin是如何知道哪些.java檔案裡面的測試方法需要執行呢?
到這個目錄下面開啟maven-surefire-plugin的實現檔案SurefirePlugin.class:
.m2\repository\org\apache\maven\plugins\maven-surefire-plugin\2.20\maven-surefire-plugin-2.20\org\apache\maven\plugin\surefire

反編譯出來,在getDefaultIncludes裡面發現了答案:所有符合尾碼Test*.java, Tests.java, TestCase.java結尾的Java檔案都作為執行單元測試的候選,

Java裡單元測試的靈活之處在於可以給同一class裡的不同方法指定不同的Category:

然後用命令列mvn install加上參數-P SlowTests只執行category為SlowTests的那些方法:


關於@Category註解的更多進階用法,參考我的SAP Community 部落格: Run only given sets of your unit test via @Category。

要擷取更多Jerry的原創技術文章,請關注公眾號"汪子熙"或者掃描下面二維碼:

ABAP和Java的單元測試Unit Test

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.