ant整合junit自動化測試,ant整合junit

來源:互聯網
上載者:User

ant整合junit自動化測試,ant整合junit

一. 使用Junit進行測試

1. Java業務代碼:

public class HelloWorld {// 測試返回"world"public String hello() {return "world";}// 測試返回"hello"public String world() {return "hello";}// 測試為空白public String nil() {return null;}// 測試不為空白public String notNil() {return "abc";}// 測試拋出異常public String ext() {return null;}}

2. 使用junit3測試, 繼承TestCase

import junit.framework.TestCase;public class HelloWorldTest extends TestCase {private HelloWorld helloWorld; @Overrideprotected void setUp() throws Exception {helloWorld = new HelloWorld();System.out.println("helloWorld init");}public void testHello() {String str = helloWorld.hello();assertEquals("測試world失敗", str, "world");}public void testWorld() {String str = helloWorld.world();assertEquals("測試world失敗", str, "hello");}public void testNotNil() {assertNotNull("對象為空白", helloWorld.notNil());}public void testNil() {assertNull("對象不為空白", helloWorld.nil());}public void testExt() {try {helloWorld.ext();fail("沒有拋出異常");} catch (NumberFormatException e) {}}@Overrideprotected void tearDown() throws Exception {System.out.println("hello world destory");helloWorld = null;}}

4. 使用junit4測試, 使用註解

import org.junit.After;import org.junit.Before;import org.junit.Test;import static org.junit.Assert.*;   // 靜態引入, assertEquals相容junit3public class HelloWorldTest {private HelloWorld helloWorld; @Beforepublic void setUp() {helloWorld = new HelloWorld();}@Testpublic void testHello() {String str = helloWorld.hello();assertEquals("hello測試失敗",str,"world");}@Testpublic void testWorld() {String str = helloWorld.world();assertEquals("world測試失敗",str, "hello");}@Testpublic void testNil() {assertNull("對象不為空白",helloWorld.nil());}@Testpublic void testNotNil() {assertNotNull("對象為空白", helloWorld.notNil());}@Test(expected=NumberFormatException.class)public void testExt() {helloWorld.ext();}@Afterpublic void tearDown() {helloWorld = null;}}





java ant怎測試Junit ?

你問的是 ant 怎麼調用/啟動junit 的測試類別嗎?
 
ant 執行junit測試的問題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.