栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

EE308 LAB 11 Software Testing

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

EE308 LAB 11 Software Testing

The link Your ClassEE308 MIEC
The link of Requirement of This AssignmentLAB 11 Software Testing
The Aim of This AssignmentSoftware Testing
MU STU ID and FZU STU ID19103387_831902225
Preparation

Learn related knowledge about Junit Test for Java and Unittest for python. You can finish the following assignment or test Your Project.

Task
  1. Here are Junit Test task and Unittest task for choose. If you are good at Java , we suggest you choose the first one, if you are good at Python, then, the latter one.
  2. Follow the requests and tips, complete the test task .
Requirements
  1. You should be familiar with Junit Test or Unittest and the usage of these tools.Such as ‘assert, suite, timeout’, check problems for detail.
  2. Fix the missing codes according to requirement for every problem.
Junit Test based on Java

1. Junit assert

AssertionsTest.java

import static org.junit.Assert.*;
import org.junit.Test;
 
public class AssertionsTest {
    String obj1 = "junit";
    String obj2 = "junit";
    String obj3 = "test";
    String obj4 = "test";
    String obj5 = null;
    int var1 = 1;
    int var2 = 2;
    int[] arithmetic1 = { 1, 2, 3 };
    int[] arithmetic2 = { 1, 2, 3 };
 
    @Test
    public void test() {
        // add assert test code between Begin and End, no other change allowed 
        
		//assertTrue(var1 < var2); for example
		assertEquals(obj1, obj2);
		assertTrue(var1 < var2);
		assertFalse(var1 > var2);
		assertNotNull(obj3);
		assertNull(obj5);
		assertArrayEquals(arithmetic1, arithmetic2);
        
    }
 
}

2. Junit time test

TestTimeOut.java

import org.junit.Test;

public class TestTimeOut {

    // Fix timeout assert in Test function below. Test fail if running 1000ms longer
    
	
    @Test(timeout=1000)
    public void test() {
        while(true){}
    }
    
}

3. Junit parameterized test

ParameterTest.java

import static org.junit.Assert.assertEquals; // static import

import java.util.Arrays;
import java.util.Collection;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import step1.Calculator;



@RunWith(Parameterized.class)
public class ParameterTest {

    private int input11;
    private int input22;
    private int expected;

    public ParameterTest(int input11, int input22, int expected){
        this.input11 = input11;
        this.input22 = input22;
        this.expected = expected;
    }

    @Parameters
    public static Collection prepareData(){

        

        
    	Object o[][] = {{1,2,3},{3,2,1},{5,3,2},{2,3,1}};
    	return Arrays.asList(o);
		

    }

    @Test
    public void testSub(){
        Calculator cal = new Calculator();
        assertEquals(cal.sub(input11, input22), expected);
    }
}

4. Junit Exception Test

JunitException.java

import static org.junit.Assert.*;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import step2.Person;

 
public class JunitException {

    

    
	@Test(expected=IllegalArgumentException.class)
  	

    public void checkage() {
    Person person = new Person();
    person.setAge(-1);
    }
}

5. Junit Suite Test

ParameterTest.java

import static org.junit.Assert.*;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import step3.Calculate;
import step3.CalculateTest;
import step3.Car;
import step3.CarTest;
 


//**************************************************************
@RunWith(Suite.class)
@Suite.SuiteClasses({ CalculateTest.class, CarTest.class})
public class SuiteTest {}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/675186.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号