Junit框架
package com_d1_junit; import org.junit.Assert; import org.junit.Test; /** * FileName: TestUserService * Author: lps * Date: 2022/4/21 11:12 * Sign:刘品水 Q:1944900433 * 测试类 */ public class TestUserService { /** 测试方法 1.必须是公开的 无参数 无返回值的 2.必须使用@Test注解标记 */ @Test public void testLoginName(){ UserService userService = new UserService(); String rs=userService.loginName("admin","123456"); //运行预期结果的正确性格式:断言 Assert.assertEquals("您的登录业务可能出现问题","登陆成功",rs); //userService.selectNames(); } @Test public void testSelectNames(){ UserService userService = new UserService(); userService.selectNames(); } }
package com_d1_junit; /** * FileName: UserService * Author: lps * Date: 2022/4/21 11:03 * Sign:刘品水 Q:1944900433 */ public class UserService { public String loginName(String loginName,String passWord){ if ("admin1".equals(loginName)&&"123456".equals(passWord)){ return "登陆成功"; }else { return "用户名或者密码有误"; } } public void selectNames(){ System.out.println(10/0); System.out.println("查询全部客户名称完成"); } }