1 下載Eclipse Juno版
https://eclipse.org/downloads/packages/release/juno/sr2
2 下載完成後→解壓縮→執行eclipse.exe
3 建立專案
Eclipse -> File -> New -> Java Project(1) Package Name:yu7
(2) Finish
在package上點右鍵,New -> JUnit Test Case
(1) 選New JUnit Test Case
(2) Package:org.openyu.java.junit
(3) Name:JunitTest
(4) 勾選
(5) Finish
4 程式碼
package org.openyu.java.junit;import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
public class JunitTest {
@BeforeClass
public static void setUpBeforeClass() throws Exception {
}
@AfterClass
public static void tearDownAfterClass() throws Exception {
}
@Before
public void setUp() throws Exception {
}
@After
public void tearDown() throws Exception {
}
@Test
public void test() {
System.out.println("---------------------------");
System.out.println("test java.openyu.org");
System.out.println("---------------------------");
}
}
5 在JUnit Test Case上按滑鼠右鍵→Run As→JUnit Test
6 執行結果
參考:http://java.openyu.org/2014/02/junit1-eclipsetest-case.html
沒有留言:
張貼留言