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

    1. First, I install three tools of JUnit and coverage tool.

      I build the path of the two jar files to my lab1 project according to the PPT.

    And I use the online url to install the eclemma.

    In the work with blank, I input the website of eclemma and choose the software to install, it just took me several minutes and was pretty convenient.

     2. I write the triangle class to judge wether it fuifull the conditions.

    package stLab1;
    public class riangle {    
        public String whichTri(int a, int b, int c){                
            int[] list = new int[]{a, b, c};
            for( int i = 0; i < 3; i++ ){
                for( int j = i; j < 3; j++ ){
                    if( list[i] < list[j]){
                        int temp = list[i];
                        list[i] = list[j];
                        list[j] = temp;
                    }
                }
            }
            a = list[0];
            b = list[1];
            c = list[2];
            if( c <= 0 || b + c <= a || a - c >= b || a - b >= c )
                return "noTri";        
            else if( a == b && b == c)
                return "eTri";
            else if( a == b || a == c || b ==c )
                return "iTri";
            else
                return "sTri";        
        }    
    }

      And then I write a test class for parameterized test.

    package stLab1;
    import java.util.Arrays;
    import java.util.Collection;
    
    import org.junit.Before;
    import org.junit.Test;
    import org.junit.runner.RunWith;
    import org.junit.runners.Parameterized;
    import org.junit.runners.Parameterized.Parameters;
    
    import stLab1.riangle;
    import static org.junit.Assert.*;
    
    public class TestStLab1 {
    	@RunWith(Parameterized.class)
    	public static class TestRiangle{
    		private int a;
    		private int b;
    		private int c;
    		private String expected;
    		private riangle tri = null;
    	
    		public TestRiangle(int a,int b,int c, String expected){
    			this.a = a;
    			this.b = b;
    			this.c = c;
    			this.expected = expected;
    		}
    		
    		@Before
    		public void setUp(){
    			tri = new riangle();
    		}
    		@Parameters
    		public static Collection<Object[]> getData(){
    			return Arrays.asList(new Object[][]{
    					{1,1,1,"eTri"},
    					{2,3,5,"noTri"},
    					{3,5,3,"iTri"},
    					{3,5,4,"sTri"},
    					{-2,3,5,"noTri"}
    			});
    		}
    		@Test
    		public void testWhichTri() {
    			assertEquals(this.expected, tri.whichTri(a, b, c));
    		}		
    	}
    }
    

      

    3.  Finally, I run it with five test cases and use the JUnit test method and coverage last lanunched. It passed the test with all five test cases.

    And the coverage shows almost all the lines have been tested.

    4. It's awesome to use these test tools to find faults in our codes. And with parameterized class I can test with many cases with only once running.

    Also, I meet a problem that the "JUnit couldn't......", finally I set the test folder to the source folder and solve it.

  • 相关阅读:
    Python 3.8六大新功能
    不小心删除/etc/passwd文件怎么办
    python干货三例(需基础) ​​​​
    程序员喜爱的七款热门Linux系统介绍(附下载地址)
    零代码时代即将到来?没那么简单
    来说说成功的云迁移的10个经验教训
    日本已开始提供10Gbps万兆光纤接入服务
    微软:将向安卓和苹果iOS平台推出杀毒软件Defender
    有jQuery背景,该如何用AngularJS编程思想?
    自用迷你版的Deferred
  • 原文地址:https://www.cnblogs.com/GameChina/p/5292368.html
Copyright © 2011-2022 走看看