Junit示例

package com.dialogueportal.controller;

import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import org.junit.Ignore;
import org.junit.Assert.*;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized.*;

import java.io.UnsupportedEncodingException;
import java.text.ParseException;
import java.util.Arrays;
import java.util.Collection;
import org.junit.After;
import org.junit.Test;

/**
 * @Title: LoginControllerTest.java
 * @Description: Login Manage Test Case
 * @author dubinglin
 * @version 1.0
 **/

@RunWith(SpringJUnit4ClassRunner.class)
public class LoginControllerTest {
	private static LoginController testLoginController = new LoginController();
//	private String customerNum;
//	private String userName;
//	private String password;

//	@Parameters
//	public static Collection data(){
//			return Arrays.asList(new Object[][]{
//				{"","admin","111111"},
//				{"CN00001","","111111"},
//				{"CN00001","admin",""},
//				{"CN00001","admin","111111"},
//				{"CN0001","admin","111111"},
//				{"CN00001","admi","111111"},
//				{"CN00001","admin","11111"},
//				{"CN00001","admin","111111"},
//			});
//	}
//
//	public LoginControllerTest(int param,int result){
//		this.customerNum = customerNum;
//		this.userName = userName;
//		this.password = password;
//	}
	@Ignore
	@Test
	public void square(){
		testLoginController.square(param);
		assertEquals(result,calculator.getResult());
	}

	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void testUserLogin() {
		try {
			assertEquals("normal","0",testLoginController.userLogin("CN00001","admin","111111"));
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
//		System.out.println("testUserLogin()");
	}
	@Ignore
	@Test
	public void testUserLogOut() {
		fail("Not yet implemented");
	}
	@Ignore
	@Test
	public void testUpdatePassword() {
		fail("Not yet implemented");
	}

}

packagecom.dialogueportal.controller;

importcom.dialogueportal.controller.LoginController;

import staticorg.junit.Assert.*;

 

importorg.junit.Before;

importorg.junit.Test;

importorg.junit.Assert.*;

importorg.junit.runner.RunWith;

importorg.junit.runners.Parameterized.*;

importjava.util.Arrays;

importjava.util.Collection;

 

/**

 * @Title: LoginControllerTest.java

 * @Description: Login Manage Test Case

 * @author dubinglin

 * @version 1.0

 **/

 

//参数化测试方法

@RunWith(Parameterized.class)

public classSquareTest{

privatestatic LoginController testLoginController = new LoginController();

privateString customerNum;

privateString userName;

privateString password;

@Parameters

publicstatic Collection data(){

returnArrays.asList(new Object[][]{

{"CN00001","admin","111111"},

});

}

 

//构造私有函数,对函数就行初始化

publicSquareTest(int param,int result){

this.customerNum= customerNum;

this.userName= userName;

this.password= password;

}

 

@Test

publicvoid square(){

testLoginController.square(param);

assertEquals(result,calculator.getResult());

}

}

 

常见测试方法

public classLoginControllerTest {

 

privatestatic LoginController testLoginController = new LoginController();

 

    //此方法在执行每一个测试方法之前(测试用例)之前调用 

@Before

publicvoid setUp() throws Exception {

        super.setUp(); 

        testLoginController = newLoginController("djm", "boy", 178, 24,"华东政法"); 

       System.out.println("setUp()");

}

 

    //此方法在执行每一个测试方法之后调用 

    @Override 

    protected void tearDown() throwsException 

    { 

        // TODO Auto-generated method stub 

        super.tearDown(); 

       System.out.println("tearDown()"); 

    }

   

@Test

publicvoid testUserLogin() {

 

assertEquals("",testLoginController.userLogin()); 

       System.out.println("testGetSex()");

}

 

@Test

publicvoid testUserLogOut() {

assertEquals("",testLoginController.userLogOut());

fail("Notyet implemented");

}

 

@Test

publicvoid testUpdatePassword() {

assertEquals("",testLoginController.updatePassword());

fail("Notyet implemented");

}

 

}

 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值