Warning: Undefined array key "HTTP_ACCEPT_LANGUAGE" in /d/web/wudimei.com/www/W/M/Lang.php on line 5

Deprecated: explode(): Passing null to parameter #2 ($string) of type string is deprecated in /d/web/wudimei.com/www/W/M/Lang.php on line 5
StrutsSpringTestCase很好用 无敌美 www.wudimei.com

php程序员业余承接网页制作、软件开发。

有需要请联系13714715608

看看案例...

StrutsSpringTestCase很好用

2014-01-09 17:08:00 yang

package com.wudimei.user;

import com.opensymphony.xwork2.ActionProxy;
import org.apache.struts2.StrutsSpringTestCase;
import org.junit.Test;

/**
*
* @author rong
*/
public class UserAction2JUnitTest extends StrutsSpringTestCase {

public UserAction2JUnitTest() {
}

@Test
public void testRegister() throws Exception {

ActionProxy proxy = null;
UserAction act = null;

request.setParameter("user.username", "ddd");
request.setParameter("user.password", "333");
request.setParameter("user.email", "yaqy@qq.com");
request.setParameter("user.gender", "1");
request.setParameter("user.realname", "楊慶榮");
request.setParameter("password2", "");

proxy = getActionProxy("/user/perform_register.do");
act = (UserAction) proxy.getAction();

String result = proxy.execute();
System.out.println(result);

assertEquals("register", result);

}
}


比起我自己寫的土辦法測試要好多了,我寫的是這樣的:


package com.wudimei.user;


import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class UserActionJUnitTest {

public UserActionJUnitTest() {
}

@BeforeClass
public static void setUpClass() {
}

@AfterClass
public static void tearDownClass() {
}

@Before
public void setUp() {
}

@After
public void tearDown() {
}

@Test
public void testPerform_register() throws Exception {

BeanFactory beanFactory;
beanFactory = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
UserDao userDao;
userDao = (UserDao)beanFactory.getBean("userDao");

UserService userService = (UserService) beanFactory.getBean("userService");
userService.setUserDao(userDao);

UserAction act;
act = new UserAction();
act.setUserService(userService);


UserTable user;
user = new UserTable();
user.setUsername("yaqy12345");
user.setPassword("123456");
user.setEmail("yaqy2qq.com");
user.setGender(1);
user.setRealname("yang");
act.setUser(user);

act.setPassword2("123456");

String res = act.perform_register();

System.out.println( "res:" + res + " ,msg:" +act.getMsg() );
assertTrue( res.equals("register") );
}


}



聯絡我們

我們期待收到您的消息

CAPTCHA
表單提交成功!
To activate this form, sign up at
https://startbootstrap.com/solution/contact-forms
發送消息時出錯!