全国大学生软件测试开发者测试大赛笔记总结

(1)常用头文件

import static org.junit.Assert.assertEquals;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import org.junit.AfterClass;
import org.junit.BeforeClass;

(2)抛出异常

//(一)(每一个测试方法都要写),2.用for循环赋值
@Test(timeout = 4000)public void test ()  throws Throwable  {}

(3)暴力赋值

用for实现大量赋值,可以保证判真判假都至少出现一次
for(int i=0;i<10;++i) {HashSet<Integer> hs = new HashSet<Integer>();for(int j=0+i;j<10+i;++j){hs.add(j);}nb.learn(i, hs);}

(4)浮点数

**************************************************
//浮点数测试第三个参数为精度:assertEquals(1.0, double0, 0.01);

(5)关于转义字符

//关于转义字符要加上:'\' ==>>Jipa.removeComment(";111()2;\"2");
//java中\s表示空白符,输入时要加\,   \\s

(6)关于集合

//关于集合HashMap<String,Integer> hashMap =new HashMap<String, Integer>();List<?> l = new ArrayList<>();//函数返回List<>用新的对象接收之后断言list.sizeList<?> l = new LinkedList<>();Map<String, Integer> m = new HashMap<>();Collection<Integer>c=new ArrayList<Integer>();Collection<Integer> c = Arrays.asList(10, 9, 7, 11, 12);Set<Map.Entry<K,V>>entry=new Map<String,ClassRoom>().entrySet();Map.entrySet();

(7)容器

Iterator<String> i = set.iterator();String st = i.next();Iterator迭代器hasNext() 如果仍有元素可以迭代,则返回 true。next()

(8)关于图

//关于图
Graph类中有Vertex静态内部类:final Graph.Vertex<Integer> v1 = new Graph.Vertex<Integer>(1);
Vertex:顶点
edge:边
先构造顶点,图Graph加入顶点。构造边,图Graph加入边。图加入顶点和边。

(9)常用断言方法

assertFalse()assertTrue()assertNull()assertNotNull()assertEquals(a,b);//谁在右边谁就是but

(10)测试private

//(一)测试private
public class Test {private static Class class1;private static 所要测试的类名 v;@BeforeClasspublic static void beforeClass() throws Exception{class1=Class.forName("net.mooctest.Variable");//类的位置}//测试类的私有构造函数@Testpublic void test()throws Exception{Constructor c=class1.getDeclaredConstructor(String.class);c.setAccessible(true);类名 v=(类名)c.newInstance("对应类型参数");}//测试类的私有有参方法@Testpublic void test1()throws Exception{Method method=class1.getDeclaredMethod("方法名",String.class);//String.class为参数method.setAccessible(true);//设置为可以访问私有函数method.invoke(v, "taohao");//对方法传参}@AfterClasspublic static void afterClass(){System.out.println("===测试完成将对象赋值为null===");}}

(11)测试异常字符串

@Rule
public ExpectedException expectedException = ExpectedException.none();@Test(timeout = 4000)public void test () {expectedException.expect(IllegalArgumentException.class);expectedException.expectMessage("The length of product's name cannot longer than 20: ");//写方法,构造对象 ,上一条语句就是测试这一句的异常输出
}

(12)测试异常

try{}catch{ assertEquals(FileNotFoundException.class,e.getClass());
}

(13)Scanner测试

//Scanner测试
//待测1
public static int readValue(){Scanner in = new Scanner(System.in);String tmpInt = in.nextLine();if (isNumeric(tmpInt))return Integer.parseInt(tmpInt);elsereturn 0;}//待测2
public static String getFileName(){Scanner in = new Scanner(System.in);System.out.println("Enter the full path to the file or type q to quit :");return in.nextLine();}//这种需要输入的不用从键盘输入
//需要这种测试:
@Test(timeout = 4000)public void test()  throws Throwable  {String data = "ss";//固定int s;//根据待测方法返回值类型InputStream stdin = System.in;//固定try { System.setIn(new ByteArrayInputStream(data.getBytes())); //固定s=Jipa.readValue();//可变(待测方法)} finally{ System.setIn(stdin); //固定}assertEquals(0,s);}

(14)输出测试

//System.out.println输出测试
public class WelcomePageTest {private PrintStream console = null;private ByteArrayOutputStream bytes = null;@Beforepublic void setUp() {bytes = new ByteArrayOutputStream();console = System.out;// 获取System.out 输出流的句柄System.setOut(new PrintStream(bytes));//将原本输出到控制台Console的字符流重定向到bytes}@Afterpublic void tearDown() {System.setOut(console);}@Testpublic void test() {String massage= "Welocme to Test.";//为构造函数建立参数WelcomePage welcomePage = new WelcomePage(massage);//创建类的对象welcomePage.showWelcomeMessages();//调用函数String expected = new String("Welocme to Test.");assertEquals(expected,bytes.toString().trim().replace("\r",""));//"\r\n", windows系统的换行方式}
}

(15)对于一般测试出现超时

//对于一般测试出现超时:
@Test(timeout = 4000)public void Test()  throws Throwable  {String data = "2222222";InputStream stdin = System.in;try { System.setIn(new ByteArrayInputStream(data.getBytes()));//在这里写测试语句,调用函数}finally{System.setIn(stdin);}}

(16)空参数

Helper.setDifference((char[]) null, (char[]) null);

(17)测试文件

//测试文件,文件放在这个里面
String fp = "src/main/resources/net/mooctest/demo.txt";
//向文件中写内容:一try {FileWriter writer=new FileWriter(fp);writer.write("abccba\n");writer.close();} catch (IOException e) {e.printStackTrace();}
//向文件中写内容:二
String demo = Anagram.class.getResource("demo.txt").getPath();
File df = new File(demo);
BufferedWriter out= new BufferedWriter(new FileWriter(df));//或者BufferedWriter out = null;  try {out = new BufferedWriter(new FileWriter(df));} catch (IOException e) {e.printStackTrace();}try {out.write("brain\n");out.write("fuck\n");out.write("hello\n");out.write("hi\n");out.close();} catch (IOException e) {e.printStackTrace();}
/try {FileWriter writer=new FileWriter(fp);writer.write("abccba\n");writer.write("\n");writer.write("abccba\n");writer.write("abccba\n");writer.write("abccba\n");writer.close();} catch (IOException e) {e.printStackTrace();}

(18)assertEquals报错

assertEquals报错
expected:<...?:false Directory:[]>
but was:<...?:false Directory:[ {}]>
不是少了[]和{},而是少了空格和{}。expected:<...?:false Directory:[]{}>but was:<...?:false Directory:[ ]{}>
少了空格

全国大学生软件测试开发者测试大赛笔记总结相关推荐

  1. 全国大学生软件测试大赛Web应用测试(四)Selenium功能测试得分技巧

    全国大学生软件测试大赛Web应用测试(四)Selenium功能测试得分技巧 WebDriver API 的使用 Java Selenium的三种等待方式 1.强制等待 2.隐性等待 3.显性等待 元素 ...

  2. 全国大学生软件测试大赛web应用测试,我院在全国大学生软件测试大赛总决赛中荣获佳绩...

    为推进特色化示范性软件学院建设和软件人才培养,提高高校学生专业素养以及对专业知识的应用能力,11月22日,全国大学生软件测试大赛总决赛于线上和线下分别举行.本次大赛由全国信息技术标准化技术委员会和软件 ...

  3. android 测试 大赛,轻量级android应用自动测试工具-2017全国大学生软件测试大赛.pdf...

    轻量级android应用自动测试工具-2017全国大学生软件测试大赛 DroidBot: A Lightweight Android App Testing Bot 轻量级Android应用自动测试工 ...

  4. 全国大学生软件测试大赛Web应用测试(一)赛项简介

    全国大学生软件测试大赛Web应用测试(一)赛项简介 web应用测试环境配置所需资料链接 Selenium功能测试 Jmeter性能测试 Web众包测试 在全国大学生软件测试大赛中Web应用测试共包含三 ...

  5. 全国大学生软件测试大赛Web应用测试(五)Jmeter性能测试环境配置

    全国大学生软件测试大赛Web应用测试(五)Jmeter性能测试环境配置 web应用测试环境配置所需资料链接 JMeter客户端下载 Badboy客户端下载 web应用测试环境配置所需资料链接 JMet ...

  6. 全国大学生软件测试大赛Web应用测试(六)Jmeter性能测试具体流程

    全国大学生软件测试大赛Web应用测试(六)Jmeter性能测试具体流程 Jmeter性能测试环境配置. Jmeter性能测试得分技巧 1.登录慕测官网 2.点击练习.搜索关键词"Web应用测 ...

  7. 全国大学生软件测试大赛Web应用测试(二)Selenium功能测试环境配置

    全国大学生软件测试大赛Web应用测试(二)Selenium功能测试环境配置 环境配置指南 web应用测试环境配置所需资料链接 配置JAVA 配置Eclipse 配置mooctest 配置ChromeD ...

  8. 全国大学生软件测试大赛Web应用大赛常用测试语句

    全国大学生软件测试大赛Web应用大赛常用测试语句 1:窗口最大化 driver.manage().window().maximize(); 2:句柄 //获取界面title //driver.getT ...

  9. 全国大学生软件测试大赛Web应用测试(三)Selenium功能测试具体流程

    全国大学生软件测试大赛Web应用测试(三)Selenium功能测试具体流程 Selenium功能测试环境配置. Selenium功能测试得分技巧 1.登录慕测官网 2.点击练习.搜索关键词" ...

最新文章

  1. Java单例模式个人总结(实例变量和类变量)
  2. Java学习总结:14
  3. hdu 4033 二分几何
  4. Java protect属性
  5. android:windowsoftinputmode=“adjustresize” 无效的解决办法
  6. Working context and Functional profile
  7. python请求模块requests的session不能保存cookies的情况
  8. python与开源_Github上Top20 Python与机器学习开源项目推荐
  9. C++初学之 3. ASCII数值的应用(大小写变换)
  10. php 正则忽略空白,(PHP)正则表达式-忽略空白
  11. 使用Javascript动态添加和删除元素
  12. 排序算法之时间复杂度O(n2)
  13. VB写的软件加壳都没用,超强反调试反破解分析,检测OD调试器
  14. 苹果开发者注册了邓白氏编码不能用,查询时提示该组织不存在怎么办?
  15. Innovus update_io_latency
  16. c#ip138自动获取代码
  17. Vue面试题你学会多少
  18. 报500服务器内部错误解决思路
  19. 用vscode调试远程服务器的php
  20. UltraISO 制作系统启动盘教程

热门文章

  1. 编码转换使用java_java编码转换的详细过程
  2. 喜大普奔——Mapbox GL JS支持多种投影了
  3. 总投资1478亿!三星表示停止LCD 面板,转换为QD-OLED
  4. 2022华为杯数学建模研赛F题思路与分析(1)
  5. 使用C++11实现线程安全的单例模式
  6. php绕过refer,绕过referer检测url跳转
  7. 电脑安全莫依赖影子系统(或冰封系统)
  8. QQ电脑版取消转义符输入表情
  9. 【py脚本】(小记)Lableme 的json转yolo的txt(仅方框)/多边形labelme转coco/关键点检测labelme转coco/yolo-voc-yolo
  10. 万字精华总结RocketMQ的常见用法(案例+图)