单元测试JUnit4 Ctrl + Shift + T
单元测试
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);
}
单元测试JUnit4 Ctrl + Shift + T的更多相关文章
- eclipse通过ctrl+shift+t无法找到源文件类的解决方法
通过ctrl + shift + t找对应的类时,类明明存在,并且也在编译路径下,但就是查找不到,一个可能的原因就是eclipse为类建立的索引出了问题. 解决的方法是:找到项目所在工作空间下的.me ...
- 关闭ctrl+shift+d截图
关闭ctrl+shift+d截图,最近用sublime text3的时候,用ctrl+shift+d,总是跳出来截图,找了半天,原来是百度浏览器的截图功能快捷键是ctrl+shift+d, 关掉即可
- 转--Eclipse中ctrl+shift+r与ctrl+shift+t的区别
Eclipse中ctrl+shift+r与ctrl+shift+t的区别 标签: 快捷键工作区文件搜索打开资源文件 2016-09-13 15:44 292人阅读 评论(0) 收藏 举报 分类: e ...
- MyEclipse使用总结——MyEclipse文件查找技巧 ctrl+shift+R ctrl+H
一.查找文件 使用快捷键[ctrl+shift+R]弹出弹出文件查找框,如下图所示: 二.查找包含某个字符串的文件 使用快捷键[ctrl+H]在弹出对话框中选File Search选项,然后在第一个文 ...
- Ctrl+Shift+F12切换最大化编辑器
常用快捷键(keymaps:Default情况下) Esc键编辑器(从工具窗口) F1帮助千万别按,很卡! F2(Shift+F2)下/上高亮错误或警告快速定位 F3向下查找关键字出现位置 F4查找变 ...
- ctrl+shift+del 清理火狐缓存,解决页面显示错乱问题
ctrl+shift+del 清理火狐缓存,解决页面显示错乱问题
- eclipse 中的注释 快捷键-添加/* */注释-Ctrl+Shift+/
(4)Ctrl+Shift+/ 说明:添加/* */注释 (5)Ctrl+Shift+\ 说明:消除/* */注释 更多:http://blog.csdn.net/wjeson/article/det ...
- Delphi 提示在Delphi的IDE中,按Ctrl+Shift+G键可以为一个接口生成一个新的GUID。
对于Object Pascal语言来说,最近一段时间最有意义的改进就是从Delphi3开始支持接口(interface),接口定义了能够与一个对象进行交互操作的一组过程和函数.对一个接口进行定义包含两 ...
- myeclipse ctrl+shift+F失效
因为在使用搜狗输入法,切换到英文状态,输入ctrl+shift+F,格式化完之后,然后再换回来
随机推荐
- BT原理分析(转)
BT种子文件结构分析,参考:http://www.cnblogs.com/EasonJim/p/6601047.html BT下载,参考:http://baike.baidu.com/item/BT下 ...
- Xcode: This device is no longer connected error
Quit the xcode and connect again will all right.
- 在C++ 程序中调用被C 编译器编译后的函数,为什么要加extern “C”
首先,作为extern是C/C++语言中表明函数和全局变量作用范围(可见性)的关键字,该关键字告诉编译器,其声明的函数和变量可以在本模块或其它模块中使用. 通常,在模块的头文件中对本模块提供给其它模块 ...
- 怎样在ubuntu 系统上为 php 加上 redis 扩展
近期一个项目.,想用redis 作为数据库,php是不待redis 扩展,必须安装,怎么安装呢?我在网上找的非常多资料发现都是预编译的.但都没成功.于是就找了第二种方法是不须要编译直接安装就能够了. ...
- vue2.0 自定义 图片上传(UpLoader)组件
1.自定义组件 UpLoader.vue <!-- 上传图片 组件 --> <template> <div class="vue-uploader"& ...
- WPF 基础到企业应用系列1——开篇故意
參考资料 提到參考资料,大家第一感觉就是MSDN,当然我也不例外.这个站点基本上是学习微软技术的首选站点,除了这个站点以外,我还參考了非常多其它的社区和站点,基本上都在.NET 技术社区之我见(英文篇 ...
- pyqt5 学习总结
关于基类 一般的文件都会基于QWidget,QtWidgets.QMainWindow 或QDialog,like this class Example(QWidget): QWidget类是所有用户 ...
- 随便写一点最近开发遇到的问题和解决方法 大部分关于laravel和php
laravel里要想对对象进行自己设计的排序(usort()), 得用匿名方法, 原声php就不用 php里面可以随便写html代码, 比如可以把html直接后缀名改成.php, 然后在任何地方& ...
- node JS 微信开发
JS-SDK 要点 微信测试号; 扫码登录;无需认证(只是名称统一为微信测试号)http://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=sandbox/logi ...
- MySQL安装过程中出现“APPLY security settings错误”的解决方式
***********************************************声明*************************************************** ...