zoukankan      html  css  js  c++  java
  • 软件测试实验二

    《软件测试》实验

    实验二 单元测试                                                       

    实验目的

    (1) 用JUnit编写单元测试;

    (2) 学习代码覆盖率和性能监测工具的使用;

    实验内容

    1、 在博客园http://www.cnblogs.com/开通自己的技术博客

    关注http://www.cnblogs.com/mjutest

    并写一段个人简介(不少于100字)

    2、 学习单元测试和代码覆盖率工具的使用

    (1)写一个程序,用于分析一个字符串中各个单词出现的频率,并将单词和它出现的频率输出显示。(单词之间用空格隔开,如“Hello World My First Unit Test”);

    (2)编写单元测试进行测试;

    (3)用ElcEmma查看代码覆盖率,要求覆盖率达到100%。

    import java.util.HashMap;

    import java.util.Map;

    public class Test {

    private static String WORD = "0";                                  

    private static String SENTENCE = "1";

    public static Map<String, Integer> getCount(String str) {

    str = str.replace(".", "#");                                        

    str = str.replace("?", "#");

    str = str.replace("!", "#");

    int wordCount = str.split(" ").length;

    int sentenceCount = str.split("#").length;

    Map<String, Integer> map = new HashMap<String, Integer>();

    map.put(WORD, wordCount);

    map.put(SENTENCE, sentenceCount);

    return map;

    }

    public static void main(String[] args) {

    Map<String, Integer> map = getCount("Hello World My First Unit Test");

    System.out.println("单词数量:   "+map.get(WORD));

    System.out.println("句子数量:   " + map.get(SENTENCE));

    }

    }

    3、  学习单元测试代码覆盖率工具的使用

    (1)把一个英语句子中的单词次序颠倒后输出。例如输入“how are you”,输出“you are how”;

    (2)编写单元测试进行测试;

    (3)用ElcEmma查看代码覆盖率,要求覆盖率达到100%。

    package cn.zhi.mju;

    import java.util.Scanner;

    public class Main {

    public static void main (String[] args){

    Main a = new Main();

    a.View();

    }

    public void findWord(String str){

    String[] arrayWord =str.split(" ");

    for(int i=arrayWord.length-1;i>=0;i--){

    System.out.print(arrayWord[i]+" ");

    }

    }

    public void View(){

    Scanner input =new Scanner(System.in);

    System.out.println("请输入字符串,单词用空格隔开,回车结束:");

    String str=input.nextLine();

    Main a = new Main();

    a.findWord(str);

    }

    }

  • 相关阅读:
    python类方法和静态方法
    42个创意户外广告设计
    50免费为移动设计和开发的PSD文件极力推荐
    40个高品质的免费商业PSD文件
    10 个有用免费 CSS3 强大工具
    10个方便的在线CSS代码生成器,网页设计师必备!
    对makefile中,变量定义中 通配符的理解
    GNU make manual 翻译(八十七)
    GNU make manual 翻译(八十九)
    GNU make manual 翻译(八十五)
  • 原文地址:https://www.cnblogs.com/lingxiaohai/p/5356384.html
Copyright © 2011-2022 走看看