软件测试
package com.alan.test;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
public class CalculatorTest {
public static Calculator calculator = new Calculator();
@Before
public void setUp() throws Exception {
}
@Test
public void add() {
calculator.add(2);
calculator.add(2);
assertEquals(4,calculator.getResult());
}
@Test
public void substract() {
calculator.substract(2);
assertEquals(2,calculator.getResult());
}
/**
* 方法没有实现,在此用Ignore跳过此测试
*/
@Ignore
public void multiply() {
calculator.multiply(10);
}
/**
* 期望抛出异常
* @throws Exception
*/
@Test(expected = Exception.class)
public void divide() throws Exception {
calculator.divide(0);
}
@Ignore
public void square() {
}
/**
* 执行代码超过一定时间自动结束
*/
@Test(timeout = 1000)
public void squareRoot() {
calculator.squareRoot(9);
}
@Ignore
public void clear() {
}
}
package com.alan.test;
import org.junit.After;
import org.junit.Before;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.*;
@FixMethodOrder(MethodSorters.JVM)
public class JDBCDemoTest {
private static JDBCDemo jdbcDemo = new JDBCDemo();
/**
* @Before 任何测试程序执行之前,都要调用此方法
*/
@Before
public void createDb() {
jdbcDemo.createDb();
}
@Test
public void insert() {
Map param=new HashMap();
param.put("id","7");
param.put("name","alan");
param.put("password","123456");
jdbcDemo.insert(param);
}
@Test
public void getAll() {
jdbcDemo.getAll();
}
/**
* @After 最后执行此程序
*/
@After
public void close() {
jdbcDemo.close();
}
}
网友评论