1个回答
展开全部
package JUnit.Test;
import static org.junit.Assert.*;
import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.enjoyor.pojo.Userinfo;
import com.enjoyor.service.UserloginService;
import com.enjoyor.util.MD5;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:applicationContext.xml"})
public class LoginTest {
@Autowired
private UserloginService userservice;
@Test
public void testlogin() {
String usercode="admin";
String password="123456";
List<Userinfo> users=userservice.checkUserInfo(usercode);
if (users.size()!=0){
String pwd=users.get(0).getUserpwd();
if (pwd.compareTo(MD5.toMD5(password))==0) {
assertEquals("soul", users.get(0).getUsername());
}
}
}
}
import static org.junit.Assert.*;
import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.enjoyor.pojo.Userinfo;
import com.enjoyor.service.UserloginService;
import com.enjoyor.util.MD5;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:applicationContext.xml"})
public class LoginTest {
@Autowired
private UserloginService userservice;
@Test
public void testlogin() {
String usercode="admin";
String password="123456";
List<Userinfo> users=userservice.checkUserInfo(usercode);
if (users.size()!=0){
String pwd=users.get(0).getUserpwd();
if (pwd.compareTo(MD5.toMD5(password))==0) {
assertEquals("soul", users.get(0).getUsername());
}
}
}
}
追问
形如这样。
@RequestMapping("/test1")
public ModelAndView test1(String parameter) throws Exception {
//something
}
追答
@Test
public ModelAndView test1(String parameter) throws Exception {
//do something
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询