Technical content
System testing is essential to identify issues within the system. Through functional testing, defects are found and corrected to ensure the system has no flaws. During testing, it is confirmed that the system meets customer requirements, and any issues or shortcomings are addressed promptly. After testing, a conclusion is drawn.
Testing Objectives
During the development cycle of the hotel management system, system testing is an indispensable and patient process. Its importance lies in being the last line of defense for system quality and reliability, as well as the final check in the entire development process. System testing aims to avoid problems users may encounter during use, enhancing user experience. To prevent this, multiple perspectives and scenarios must be considered to discover and resolve defects. Testing also allows understanding of the system's quality, weather its functions are complete, and if the logic is smooth. A qualified testing process significantly improves system quality and usability. The goal of testing is to verify if the system meets the specifications defined in the requirements document and to identify any discrepancies. During testing, issues should be considered from the user's perspective to avoid unrealistic scenarios that may waste time and lead to mismatched results.
Functional Testing
Testing of system function modules is conducted using methods such as clicking, inputting boundary values, and validating required vs non-required fields through black-box testing. Test cases are written, and testing is performed based on these cases, leading to test conclusions.
Login functionality test plan: When logging into the system, verification is done through account and password features. Users must enter content matching data stored in the database. If any input is incorrect, the system will prompt for a error. This interface also verifies role permissions. If a user with an admin role attempts to log in, an error will occur. Login functionality test cases are shown in the following table.
| Input Data | Expected Result | Actual Result | Result Analysis |
|---|---|---|---|
| Username: guanliyuan Password: 123456 Captcha: Correct Input | Login to the system | Successfully logged into the system | Matches the expected result |
| Username: guanliyuan Password: 111111 Captcha: Correct Input | Password error | Password error, please re-enter the password | Matches the expected result |
| Username: guanliyuan Password: 123456 Captcha: Incorrect Input | Captcha error | Captcha information error | Matches the expected result |
| Username: empty Password: 123456 Captcha: Correct Input | Username is required | Please enter username | Matches the expected result |
| Username: guanliyuan Password: empty Captcha: Correct Input | Password error | Password error, please re-enter the password | Matches the expected result |
User management function test plan: User management includes adding, editing, deleting, and searching for users. When adding a user, check if the system enforces non-empty fields; when adding existing user information, check if the system prompts that the username is already taken; when deleting user information, check if the system validates this action; when editing user information, check if the page displays the updated information. User management test cases are shown in the following table.
| Input Data | Expected Result | Actual Result | Result Analysis |
|---|---|---|---|
| Enter basic user information | Added successfully, displayed in the user list | The user appears in the list | Matches the expected result |
| Edit user information | Edited successfully, modified information is updated | User information is updated | Matches the expected result |
| Select delete user | System asks if the user should be deleted, and after confirmation, the user is deleted | System asks if the user should be deleted, and after confirmation, the user information is not found | Matches the expected result |
| Add user without entering username | Username cannot be empty | Username cannot be empty | Matches the expected result |
| Enter existing username | Adding failed, username is duplicated | Adding failed, username is duplicated | Matches the expected result |
Testing Conclusion
The system primarily uses black-box testing by simulating user interactions to create test cases and perform testing, ensuring the correctness of the system flow. System testing is essential to make the system more complete, and the usability of the system will be higher. Testing this system aims to verify if the functional modules meet the initial design concept, confirm the correctness of each module's logic, and ensure the system does not require complex logic processing for ease of use. The ultimate goal of testing revolves around user usage. All scenarios during testing should align with user needs, avoiding deviation from the target. When encountering issues, they should be approached from the user's perspective. After a series of testing processes, the final test results show that the implemented system meets the design requirements in terms of functionality and performance.
Code reference
@IgnoreAuth
@PostMapping(value = "/login")
public R login(String username, String password, String captcha, HttpServletRequest request) {
UsersEntity user = userService.selectOne(new EntityWrapper<UsersEntity>().eq("username", username));
if(user==null || !user.getPassword().equals(password)) {
return R.error("Account or password is incorrect");
}
String token = tokenService.generateToken(user.getId(),username, "users", user.getRole());
return R.ok().put("token", token);
}
@Override
public String generateToken(Long userid,String username, String tableName, String role) {
TokenEntity tokenEntity = this.selectOne(new EntityWrapper<TokenEntity>().eq("userid", userid).eq("role", role));
String token = CommonUtil.getRandomString(32);
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
cal.add(Calendar.HOUR_OF_DAY, 1);
if(tokenEntity!=null) {
tokenEntity.setToken(token);
tokenEntity.setExpiratedtime(cal.getTime());
this.updateById(tokenEntity);
} else {
this.insert(new TokenEntity(userid,username, tableName, role, token, cal.getTime()));
}
return token;
}
/**
* Permission (Token) Verification
*/
@Component
public class AuthorizationInterceptor implements HandlerInterceptor {
public static final String LOGIN_TOKEN_KEY = "Token";
@Autowired
private TokenService tokenService;
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//Support cross-domain requests
response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
response.setHeader("Access-Control-Max-Age", "3600");
response.setHeader("Access-Control-Allow-Credentials", "true");
response.setHeader("Access-Control-Allow-Headers", "x-requested-with,request-source,Token, Origin,imgType, Content-Type, cache-control,postman-token,Cookie, Accept,authorization");
response.setHeader("Access-Control-Allow-Origin", request.getHeader("Origin"));
// When cross-domain, an OPTIONS request is first sent, here we directly return normal status for OPTIONS requests
if (request.getMethod().equals(RequestMethod.OPTIONS.name())) {
response.setStatus(HttpStatus.OK.value());
return false;
}
IgnoreAuth annotation;
if (handler instanceof HandlerMethod) {
annotation = ((HandlerMethod) handler).getMethodAnnotation(IgnoreAuth.class);
} else {
return true;
}
// Get token from header
String token = request.getHeader(LOGIN_TOKEN_KEY);
/**
* Methods that do not require permission verification are passed directly
*/
if(annotation!=null) {
return true;
}
TokenEntity tokenEntity = null;
if(StringUtils.isNotBlank(token)) {
tokenEntity = tokenService.getTokenEntity(token);
}
if(tokenEntity != null) {
request.getSession().setAttribute("userId", tokenEntity.getUserid());
request.getSession().setAttribute("role", tokenEntity.getRole());
request.getSession().setAttribute("tableName", tokenEntity.getTablename());
request.getSession().setAttribute("username", tokenEntity.getUsername());
return true;
}
PrintWriter writer = null;
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json; charset=utf-8");
try {
writer = response.getWriter();
writer.print(JSONObject.toJSONString(R.error(401, "Please log in first")));
} finally {
if(writer != null){
writer.close();
}
}
// throw new EIException("Please log in first", 401);
return false;
}
}
Database reference
-- ----------------------------
-- Table structure for token
-- ----------------------------
DROP TABLE IF EXISTS `token`;
CREATE TABLE `token` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'Primary key',
`userid` bigint(20) NOT NULL COMMENT 'User ID',
`username` varchar(100) NOT NULL COMMENT 'Username',
`tablename` varchar(100) DEFAULT NULL COMMENT 'Table name',
`role` varchar(100) DEFAULT NULL COMMENT 'Role',
`token` varchar(200) NOT NULL COMMENT 'Password',
`addtime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Add time',
`expiratedtime` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT 'Expiration time',
PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=27 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='Token table';
-- ----------------------------
-- Records of token
-- ----------------------------
INSERT INTO `token` VALUES ('9', '23', 'cd01', 'xuesheng', 'Student', 'al6svx5qkei1wljry5o1npswhdpqcpcg', '2023-02-23 21:46:45', '2023-03-15 14:01:36');
INSERT INTO `token` VALUES ('10', '11', 'xh01', 'xuesheng', 'Student', 'fahmrd9bkhqy04sq0fzrl4h9m86cu6kx', '2023-02-27 18:33:52', '2023-03-17 18:27:42');
INSERT INTO `token` VALUES ('11', '17', 'ch01', 'xuesheng', 'Student', 'u5km44scxvzuv5yumdah2lhva0gp4393', '2023-02-27 18:46:19', '2023-02-27 19:48:58');
INSERT INTO `token` VALUES ('12', '1', 'admin', 'users', 'Administrator', 'h1pqzsb9bldh93m92j9m2sljy9bt1wdh', '2023-02-27 19:37:01', '2023-03-17 18:23:02');
INSERT INTO `token` VALUES ('13', '21', 'xiaohao', 'shezhang', 'President', 'zdm7j8h1wnfe27pkxyiuzvxxy27ykl2a', '2023-02-27 19:38:07', '2023-03-17 18:25:20');
INSERT INTO `token` VALUES ('14', '27', 'djy01', 'xuesheng', 'Student', 'g3teq4335pe21nwuwj2sqkrpqoabqomm', '2023-03-15 12:56:17', '2023-03-15 14:00:16');
INSERT INTO `token` VALUES ('15', '29', 'dajiyue', 'shezhang', 'President', '0vb1x9xn7riewlp5ddma5ro7lp4u8m9j', '2023-03-15 12:58:08', '2023-03-15 14:03:48');