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");
}
}
Junit示例
最新推荐文章于 2025-06-12 15:53:24 发布