Login Register Testing - UQcsse3200/2024-studio-2 GitHub Wiki
1. Overview
The Login/Register Menu is an essential feature that allows players to login to their existing account or create a new one to start using game services. It enhances user security while also providing an intuitive user experience.
2. Testing
2.1 Register Unit Testing
2.1.1 Test User Register Success
This test verifies a successful registration attempt where all the provided details are valid. The username, email, password, and display name are randomly generated to avoid conflicts. The test checks if the registration returns a successful result and matches the provided input. However, in the Unit Testing, this test is hided as it will create lots of new users (2500 users within few weeks).
@Test
public void testRegisterUserSuccess() {
RegisterPlayFabUserRequest request = new RegisterPlayFabUserRequest();
int random = ThreadLocalRandom.current().nextInt(10000000, 99999999);
request.Username = "test" + random;
System.out.println(request.Username);
request.Email = "test" + random + "@gmail.com";
request.Password = "123456";
request.DisplayName = "test" + random;
PlayFabResult<RegisterPlayFabUserResult> result = PlayFabClientAPI.RegisterPlayFabUser(request);
// Assert that result.Result is not null
assertNotNull(result.Result, "Result should not be null");
assertEquals("test" + random, result.Result.Username);
}
2.1.2 Test User Register Fail (Password Fail)
This test simulates a registration failure due to an invalid password that does not meet the required criteria, which should be 6 - 10 characters instead of 4 characters for the password field. The system should return an error indicating invalid input parameters.
@Test
public void testRegisterUserPasswordFail() {
RegisterPlayFabUserRequest request = new RegisterPlayFabUserRequest();
request.Username = "test123";
System.out.println(request.Username);
request.Email = "[email protected]";
request.Password = "1234";
PlayFabResult<RegisterPlayFabUserResult> result = PlayFabClientAPI.RegisterPlayFabUser(request);
// Assert that result.Result is not null
assertNotNull(result.Error, "Result should not be null");
assertEquals("Invalid input parameters", result.Error.errorMessage);
}
2.1.3 Test User Register Fail (Email Fail)
This test case checks for a registration failure caused by an invalid email format, which requires string + "@" + string. The system is expected to return an error stating that the input parameters are invalid.
@Test
public void testRegisterUserEmailFail() {
RegisterPlayFabUserRequest request = new RegisterPlayFabUserRequest();
request.Username = "test123";
System.out.println(request.Username);
request.Email = "test";
request.Password = "123456";
PlayFabResult<RegisterPlayFabUserResult> result = PlayFabClientAPI.RegisterPlayFabUser(request);
// Assert that result.Result is not null
assertNotNull(result.Error, "Result should not be null");
assertEquals("Invalid input parameters", result.Error.errorMessage);
}
2.1.4 Test User Register Fail (Both Password and Email Fail)
This test simulates a scenario where both the password and email are invalid. The system should detect a password error, which has higher privilege, and return the appropriate error message.
@Test
public void testRegisterUserPasswordAndEmailFail() {
RegisterPlayFabUserRequest request = new RegisterPlayFabUserRequest();
request.Username = "test123";
System.out.println(request.Username);
request.Email = "test";
request.Password = "1234";
PlayFabResult<RegisterPlayFabUserResult> result = PlayFabClientAPI.RegisterPlayFabUser(request);
// Assert that result.Result is not null
assertNotNull(result.Error, "Result should not be null");
assertEquals("Invalid input parameters", result.Error.errorMessage);
}
2.1.5 Test User Register Fail (Email Exist)
This test ensures that registration fails when the email provided is already associated with an existing account. The system should return an error indicating that the email address is unavailable.
@Test
public void testRegisterUserEmailExistFail() {
RegisterPlayFabUserRequest request = new RegisterPlayFabUserRequest();
request.Username = "test123";
System.out.println(request.Username);
request.Email = "[email protected]";
request.Password = "123456";
PlayFabResult<RegisterPlayFabUserResult> result = PlayFabClientAPI.RegisterPlayFabUser(request);
// Assert that result.Result is not null
assertNotNull(result.Error, "Result should not be null");
assertEquals("Email address not available", result.Error.errorMessage);
}
2.1.6 Test User Register Fail (Email Exist and Password Fail)
This test covers a case where the email is already in use and the password also fails validation. The system should detect email issue rather than password issue and return the email error message.
@Test
public void testRegisterUserEmailExistAndPasswordFail() {
RegisterPlayFabUserRequest request = new RegisterPlayFabUserRequest();
request.Username = "test123";
System.out.println(request.Username);
request.Email = "[email protected]";
request.Password = "123456";
PlayFabResult<RegisterPlayFabUserResult> result = PlayFabClientAPI.RegisterPlayFabUser(request);
// Assert that result.Result is not null
assertNotNull(result.Error, "Result should not be null");
assertEquals("Email address not available", result.Error.errorMessage);
}
2.2 Login Unit Testing
It could be implemented, but it will cause throttling, making other users unable to login.