package com.meiya.selenium.lession1;
public class T {
public double add (double a ,double b ){
return (a+b);
}
public double devide (double a ,double b ){
return (a/b);
}
}
下面是测试类的代码:
package com.meiya.selenium.lession1;
import static org.junit.Assert.assertEquals;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
public class TTest {
@BeforeClass
public static void BeforeClass() {
System.out.println("BeforeClass() ");
}
@Before
public void testBefore() {
System.out.println("testBefore()");
}
@Test
public void testAdd() {
T t = new T();
double actual = t.add(1, 2);
System.out.println(actual);
assertEquals(3, actual,0.1);
}
@Test(timeout=1)
public void testDevide2() {
T t = new T();
double actual = t.devide(5, 3);
System.out.println(actual);
assertEquals(1.67, actual,0.01);;
}
@Test(expected=Exception.class)
public void testDevide3() {
T t = new T();
double actual = t.devide(5, 3);
System.out.println(actual);
assertEquals(1.67, actual,0.01);;
}
@After
public void testAfter() {
System.out.println("testAfter()");
}
@AfterClass
public static void AfterClass() {
System.out.println("AfterClass()");
}
}
初学junit4需要测试的类:package com.meiya.selenium.lession1;public class T { public double add (double a ,double b ){ return (a+b); } public double devide (double a ,double b ){ retu