单元测试

public class Calculator {
public int result = 0; public int add(int operandl, int operand2) {
result = operandl + operand2;
return result;
} public int subtract(int operandl, int operand2) {
result = operandl - operand2;
return result;
} public int multiple(int operandl, int operand2) {
result = operandl * operand2;
for (; ; ) { }
} public int divide(int operandl, int operand2) {
result = operandl / 0;
return result;
} public int getResult() {
return this.result;
} }
public class CalculatorTest {
public static Calculator cal = new Calculator(); //测试开始前只能被执行一次
@BeforeClass
public static void setUpBeforClass() throws Exception {
System.out.println(" @BeforeClass"); } //测试结束前只调用一次
@AfterClass
public static void tearDownAfterClass() throws Exception {
System.out.println("@AfterClass");
} @Before
public void setUp() throws Exception {
System.out.println("测试开始");
} @After
public void tearDown() throws Exception {
System.out.println("测试结束");
} @Test
public void testSubstract() {
cal.subtract(4, 2);
assertEquals(2, cal.getResult());
// fail("Not yet implemented");
} @Test
public void testAdd() {
cal.add(2, 2);
assertEquals(4, cal.getResult());
// fail("Not yet implemented");
} //忽略执行
@Ignore
public void testMultiply() {
fail("Not yet implemented"); } //测试用例时间不能超过2s,死循环时间超过2s
@Test(timeout = 2000)
public void testDivide() {
for (; ; ) ;
} //执行之后抛出异常才成功
@Test(expected = ArithmeticException.class)
public void testDivideByZero() {
cal.divide(4, 0);
} }

单元测试WebDriver脚本

public class dome2 {

public WebDriver driver;
String baseUrl="https://www.baidu.com/";
@Before
public void setUp(){
System.setProperty("webdriver.firefox.bin", "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
driver = new FirefoxDriver();
}
@After
public void tearDown(){
driver.quit();
}
@Test
public void test(){
driver.get(baseUrl);
}

最新文章

  1. 【IOS 开发】Object - C 入门 之 数据类型详解
  2. [Spring MVC] - 地址路由使用(一)
  3. Extjs 控件属性(部分)
  4. 给 Android 开发者的 RxJava 详解
  5. lex&yacc5--YYSTYPE
  6. YII 小部件 解决多选按钮和单选按钮不在同一水平上 'separator'=>' '
  7. QT中使用google breakpad捕获程序崩溃异常
  8. guava学习,集合专题
  9. JavaScript数据类型之布尔类型
  10. mysql 监控工具(windows版本)
  11. .net Kafka.Client多个Consumer Group对Topic消费不能完全覆盖研究总结(二)
  12. Yii2 RbacController示例
  13. Kylin知识点介绍
  14. while与do/while循环
  15. asp.net 中日期的格式化显示的方法
  16. iOS UI基础-3.0图片浏览器及plist使用
  17. Daily Scrum4 11.6
  18. 34、疯狂java讲义第三版
  19. jenkins配置maven
  20. OpenERP Web开发

热门文章

  1. Android 你应该注意的开发规范
  2. intent 支持的action 动作
  3. MySQL常用SQL整理
  4. PS 如何制作眼泪效果
  5. angular - 介绍
  6. 【LeetCode-面试算法经典-Java实现】【002-Add Two Numbers (单链表表示的两个数相加)】
  7. 免费DNSserver有哪些?
  8. (二)MVVMLight 关联View和ViewModel
  9. UVA - 11354Bond最小生成树,LCA寻找近期公共祖先
  10. POJ 2480 Longge's problem 积性函数