-
Notifications
You must be signed in to change notification settings - Fork 4
Achievements System Testing
Test achievement unlocking logic, i.e, the logic which decides that an achievement popup should be rendered on the screen.
The GameExtension class makes the job of testing very easy by mocking most of the libgdx and game-engine classes.
@ExtendWith(GameExtension.class)
public class AchievementStatsComponentTest {
Java Lang Reflect: Used to access private methods and private fields of a class from the testing suite and make them accessible for testing purposes
JUnit: Used for assertions (mostly value equality) and class extendWitih
decorator plugins.
The most sensitive logic of the achievements system is to check if - given the in game time, item count and health, a certain achievement is valid or not. An event must be dispatched if the achievement is valid given the time, item count and health constraints. An event called updateAchievement
can only be dispatched if the particular achievement satisfies the constraints, in which case it is unlocked and perfectly valid.
private Method getIsValidMethod() throws NoSuchMethodException {
Method method = AchievementsStatsComponent.class
.getDeclaredMethod("isValid",
BaseAchievementConfig.class);
method.setAccessible(true);
return method;
}
The veteran achievement gets unlocked if the user survives for 10, 15 or 20 minutes. It is assumed that the JSON achievement details configuration is valid.
@Test
void shouldCorrectlyValidateVeteranAchievements() throws
IllegalAccessException,
InvocationTargetException, NoSuchMethodException {
Method method = getIsValidMethod();
AchievementsStatsComponent component = generateEntity()
.getComponent(AchievementsStatsComponent.class);
for (BaseAchievementConfig a : getList()) {
component.setTime(999999999);
component.setHealth(-1);
if (a.name.equals("Veteran")) {
assertEquals(method.invoke(component, a), true);
} else {
assertEquals(method.invoke(component, a), false);
}
}
}
- Veteran
- Game Breaker
- Tool Master
Test GameRecords
and GameInfo
persistence logic. More information about this flow can be found here
This setup was necessary in order to make sure that the test suite's FileLoader
does not communicate with the filesystem outside the project folder. So all the JSON operations were redirected to test files inside source/assets/test/files
directory and thats where fully fledged test read and write operations took place. This was necessary to test the GameInfo
which kept a tab of the number of games played. The incremement logic was tested as well which happens as soon as a player dies.
/**
* Change the value of a private static final variable
*
* @param field the private static final variable field
* @param newValue the value to replace
*/
static void setFinalStatic(Field field, Object newValue) {
try {
field.setAccessible(true);
Field modifiersField = Field.class.getDeclaredField("modifiers");
modifiersField.setAccessible(true);
modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
field.set(null, newValue);
} catch (Exception ignored) {
}
}
@BeforeEach
void beforeEach() throws Exception {
// Changing the JSON file path so that the original game data in the EXTERNAL location is not affected
setFinalStatic(GameInfo.class.getDeclaredField("path"),
"test/files/gameInfoTest.json");
setFinalStatic(GameInfo.class.getDeclaredField("location"), FileLoader.Location.LOCAL);
}
For reference, these are the actual variables in the GameInfo.java
's class:
private static final String path = ROOT_DIR + File.separator + GAME_INFO_FILE;
private static final FileLoader.Location location = FileLoader.Location.EXTERNAL;
- Testing the asynchronous event queue which is used to display each popup for a fixed time interval
Camera Angle and The Player's Perspective
Achievements Trophies and Cards
πΎ Obstacle/Enemy
βMonster Manual
βObstacles/Enemies
ββ- Alien Plants
ββ- Variation thorns
ββ- Falling Meteorites
ββ- FaceHugger
ββ- AlienMonkey
βSpaceship & Map Entry
βParticle effect
[code for debuff animations](code for debuff animations)
Main Character Movement, Interactions and Animations - Code Guidelines
ItemBar & Recycle system
πΎ Obstacle/Enemy
βObstacle/Enemy
βMonster Manual
βSpaceship Boss
βParticle effects
βOther Related Code
βUML & Sequence diagram of enemies/obstacles
Scoring System Implementation Explanation
Buff and Debuff Implementation
Infinite generating terrains Implementation Explanation
Game Over Screen and functions explaination
Buffer timer before game start
Rocks and woods layout optimization
Magma and nails code implementation
Guide: Adding Background music for a particular screen
History Scoreboard - Score Details
Listening for important events in the Achievements ecosystem
Hunger and Thirst icon code guidelines
Hunger and Thirst User Testing
Buff and Debuff Manual User Testing
The New Button User Test in Setting Page
The Main Menu Buttons User Testing
Infinite loop game and Terrain Testing
https://github.com/UQdeco2800/2021-ext-studio-2.wiki.git
πΎ Obstacle/Enemy
βObstacle testing
ββ- Alien Plants & Variation Thorns
ββ- Falling Meteorites
βEnemy testing
ββ- Alien Monkeys & Facehugger
ββ- Spaceship Boss
βMonster Manual
βParticle-effect
βPlayer attack testing
ββ- Player Attack
Sprint 1
Sprint 2
Sprint 3
Sprint 4
Changeable background & Buffer time testing
Game over screen test sprint 4
New terrain textures on bonus map test sprint 4
Achievements System, Game Records and Unlockable Chapters
Musics Implementation Testing plan