???????????????????????????????????????в??У????????????????????????????С??Χ?????????????????????????????????????????????????????á?????????μ???????????????е???????????????д??main???????????в?????????????Junit??????????????????????????????????????????????????????????????????????????????й?Junit????????????????????MyElipse 8.5 ?????????
????1.??????project???????????properties-----Java Build Path-----Libraries---AddLibrary---Junit????Junit?????????????С?
????2.??project?н??????JDemo.java ?? Test.java??JDemo??????????????add()??Test????TestCase?????????£?
JDemo.java
package com.bx.testjunit;
public class JDemo {
int a;
int b;
int result;
public int add(int a??int b){
result = a + b;
return result;
}
}
Test.java
package com.bx.testjunit;
import junit.framework.TestCase;
import org.junit.After;
import org.junit.Before;
public class Test extends TestCase{
@Before
public void setUp() throws Exception {
System.out.println("Test :setUp");
}
@After
public void tearDown() throws Exception {
System.out.println("Test :tearDown");
}
public void test(){
JDemo a = new JDemo();
assertEquals(6??a.add(3?? 3));
}
}
????3.???У????Junit Test?????????????????Junit???????????????????bar?????????????????????????bar????????????????м???
?????????????????Junit3????????TestCase
???????濴???Junit4??????
package com.bx.service;
import org.junit.Test;
public class HelloWorld {
@Test
public void test(){
System.out.println("HelloWord :test");
}
}
????Junit4????????TestCase????????@Test?????expected?????