Crafting System Testing Plan Sprint Four - UQdeco2800/2022-studio-2 GitHub Wiki

Test Plan

In this sprint, we were able to test whether the Material was successfully created. This helps debug functionality and reduces errors. In addition, I tested the "Open Crafting Component" and "GameAreadisply" to make sure I can start the Crafting Table properly. To support testing and keeping a record of feature code, we've added all the Logger info to ensure proper recording and journaling, And also can give some help for testing. Also We get most class get 100% Coverage,and some class have around 75% coverage.

In this section, the components tested for sprint two and three will be discussed. The method used are:

  1. JUnit testing.
  2. Sonarcloud testing.

MaterialFactory Test

  1. SetUp the test environment
@BeforeEach
    void setUp() {
        ForestGameArea fga = mock(ForestGameArea.class);
        ServiceLocator.registerGameArea(fga);
        ServiceLocator.registerEntityService(new EntityService());
        ServiceLocator.registerPhysicsService(new PhysicsService());
        ServiceLocator.registerInputService(new InputService());
        ServiceLocator.registerRenderService(new RenderService());
        ResourceService resourceService = new ResourceService();
        ServiceLocator.registerResourceService(resourceService);

        String[] textures = {
                "images/Crafting-assets-sprint1/materials/gold.png",
                "images/Crafting-assets-sprint1/materials/rainbow_poop.png",
                "images/Crafting-assets-sprint1/materials/iron.png",
                "images/Crafting-assets-sprint1/materials/toilet_paper.png",
                "images/Crafting-assets-sprint1/materials/steel.png",
                "images/Crafting-assets-sprint1/materials/wood.png",
                "images/Crafting-assets-sprint1/materials/plastic.png",
                "images/Crafting-assets-sprint1/materials/rubber.png",
                "images/Crafting-assets-sprint1/materials/platinum.png",
                "images/Crafting-assets-sprint1/materials/silver.png"};
        resourceService.loadTextures(textures);
        String[] textureAtlases = {"images/CombatItems/animations/combatItemsAnimation.atlas"};
        resourceService.loadTextureAtlases(textureAtlases);
        resourceService.loadAll();

        GameArea gameArea = spy(GameArea.class);
        RenderService renderService = new RenderService();
        renderService.setStage(mock(Stage.class));
        GameAreaDisplay material = new GameAreaDisplay("");
        ServiceLocator.registerGameArea(gameArea);
        ServiceLocator.registerRenderService(renderService);
        ServiceLocator.registerInventoryArea(material);
        material.create();
        entity = new Entity();
    }
  1. Test constructor
@Test
    void MaterialFactory() throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        Constructor constructor = MaterialFactory.class.getDeclaredConstructor();
        constructor.setAccessible(true);
        MaterialFactory obj=(MaterialFactory) constructor.newInstance();
        obj.toString();
    }
  1. Basic Test
@Test
    void shouldCreateBaseMaterial() {
        Entity baseEntity;
        baseEntity = MaterialFactory.createBaseMaterial();
        int id = baseEntity.getId();
        assertEquals(baseEntity.getId(), id);
        assertTrue(baseEntity instanceof Entity);
    }
  1. Create Material Test

All the material use similar test methods

@Test
    void shouldCreatePoop() {
        entity = MaterialFactory.createPoop();
        assertTrue(entity.checkEntityType(EntityTypes.CRAFTABLE));
        assertTrue(entity.checkEntityType(EntityTypes.POOP));
    }

There are one method that cannot doing the test "openCrafting()" in the class OpenCraftingComponent, case there it cannot enter into the if statement, or always failed, and I try to set the player position and craftingState but it still failed, But it cloud do the Visual test it's work. And We also have some comment test one of that is broken our branch, and We can't find out how to solve it, case the setup may miss something, and difficult to do this UI test. And for the gameAreaDisPlay we got somen test worked in this class, and there are always problems with resources not being loaded or not being logged but most need UI Visual test for that and is may could reference the gameArea Test.

OpenCrafting Component Test

  1. Load all the resource we need in the test
Entity player;
    OpenCraftingComponent openCraftingComponent;
    @BeforeEach
    void setUp() {
        ForestGameArea fga = mock(ForestGameArea.class);
        ServiceLocator.registerGameArea(fga);
        ServiceLocator.registerEntityService(new EntityService());
        ServiceLocator.registerPhysicsService(new PhysicsService());
        ServiceLocator.registerInputService(new InputService());
        ServiceLocator.registerRenderService(new RenderService());
        ResourceService resourceService = new ResourceService();
        ServiceLocator.registerResourceService(resourceService);

        String[] textures = {
                "images/Crafting-assets-sprint1/crafting table/crafting_inventory_lvl1.png",
                "images/Crafting-assets-sprint1/crafting table/crafting_inventory_lvl2.png",
                "images/Crafting-assets-sprint1/widgets/craft_button_lvl1.png",
                "images/Crafting-assets-sprint1/widgets/craft_button_lvl2.png",
                "images/Crafting-assets-sprint1/widgets/exit_button_lvl1.png",
                "images/Crafting-assets-sprint1/widgets/exit_button_lvl2.png",
                "images/PauseMenu/lvl2PauseScreen.png",
                "images/PauseMenu/newPauseScreen.png",
                "images/crafting_assets_sprint2/transparent-texture-buttonClick.png",
                "images/keybind/level_1/ControlPage.png",
                "images/keybind/level_2/ControlPage.png",
                "images/CombatItems/Sprint-3/craftingTeamAssetsNoWhiteSpace/Hera.png",
                "images/Crafting-assets-sprint1/popups/number1_popup.png",
                "images/Crafting-assets-sprint1/popups/number2_popup.png",
                "images/Crafting-assets-sprint1/popups/number3_popup.png",
                "images/Crafting-assets-sprint1/popups/number4_popup.png",
                "images/Crafting-assets-sprint1/popups/number5_popup.png",
                "images/Crafting-assets-sprint1/popups/crafting_indicator.png",
                "images/Crafting-assets-sprint1/popups/arrow-top-right.png",
                "images/Crafting-assets-sprint1/popups/arrow-top-left.png",
                "images/Crafting-assets-sprint1/popups/first-mat-prompt.png",
                "images/Crafting-assets-sprint1/popups/second-mat-prompt.png",
                "images/Crafting-assets-sprint1/popups/craft-prompt.png",
                "images/Crafting-assets-sprint1/crafting table/crafting_catalogue_1_lvl1.png",
                "images/Crafting-assets-sprint1/crafting table/crafting_catalogue_1_lvl2.png",
                "images/Crafting-assets-sprint1/widgets/inventory_button_lvl1.png",
                "images/Crafting-assets-sprint1/widgets/inventory_button_lvl2.png",
                "images/Crafting-assets-sprint1/widgets/catalogue_page2_lvl1.png",
                "images/Crafting-assets-sprint1/widgets/catalogue_page2_lvl2.png",
                "images/Crafting-assets-sprint1/crafting table/crafting_catalogue_2_lvl1.png",
                "images/Crafting-assets-sprint1/crafting table/crafting_catalogue_2_lvl2.png",
                "images/Crafting-assets-sprint1/widgets/catalogue_page1_lvl1.png",
                "images/Crafting-assets-sprint1/widgets/catalogue_page1_lvl2.png",
                "images/CombatItems/Sprint-1/Level 2 Dagger 1.png",
                "images/CombatItems/Sprint-1/Level 2 Dagger 2png.png",
                "images/CombatItems/Sprint-1/Enemy_dumbbell.png",
                "images/CombatItems/Sprint-1/Level 2 Dagger 2png.png",
                "images/CombatItems/Sprint-1/Sword_Lvl2.png",
                "images/Crafting-assets-sprint1/materials/gold.png",
                "images/Crafting-assets-sprint1/materials/rainbow_poop.png",
                "images/Crafting-assets-sprint1/materials/iron.png",
                "images/Crafting-assets-sprint1/materials/toilet_paper.png",
                "images/Crafting-assets-sprint1/materials/steel.png",
                "images/Crafting-assets-sprint1/materials/wood.png",
                "images/Crafting-assets-sprint1/materials/plastic.png",
                "images/Crafting-assets-sprint1/materials/rubber.png",
                "images/Crafting-assets-sprint1/materials/platinum.png",
                "images/Crafting-assets-sprint1/materials/silver.png"
        };
        resourceService.loadTextures(textures);
        String[] textureAtlases = {"images/CombatItems/animations/combatItemsAnimation.atlas"};
        resourceService.loadTextureAtlases(textureAtlases);
        resourceService.loadAll();

        GameArea gameArea = spy(GameArea.class);
        RenderService renderService = new RenderService();
        renderService.setStage(mock(Stage.class));
        GameAreaDisplay craftingArea = new GameAreaDisplay("Underground");
        ServiceLocator.registerGameArea(gameArea);
        ServiceLocator.registerRenderService(renderService);
        ServiceLocator.registerInventoryArea(craftingArea);
        craftingArea.create();
        player = PlayerFactory.createTestPlayer();
        openCraftingComponent = new OpenCraftingComponent();
        player.addComponent(openCraftingComponent);
        player.create();
        gameArea.setPlayer(player);
    }
 @Test
    void shouldInRange() {
        player.setPosition(90, 45);
        assertTrue(openCraftingComponent.inRange(player.getPosition()));

        AssetManager assetManager = spy(AssetManager.class);
        ResourceService resourceService = new ResourceService(assetManager);
        ServiceLocator.registerResourceService(resourceService);
        GameArea gameArea = spy(GameArea.class);
        RenderService renderService = new RenderService();
        renderService.setStage(mock(Stage.class));
        GameAreaDisplay playerGuidArea = new GameAreaDisplay("");
        ServiceLocator.registerGameArea(gameArea);
        ServiceLocator.registerRenderService(renderService);
        ServiceLocator.registerPlayerGuideArea(playerGuidArea);
        ServiceLocator.registerCraftArea(playerGuidArea);
        playerGuidArea.create();
        player = new Entity();
        openCraftingComponent = new OpenCraftingComponent();
        player.addComponent(openCraftingComponent);
        player.create();
        gameArea.setPlayer(player);
        player.setPosition(100, 10);
        assertTrue(openCraftingComponent.inRange(player.getPosition()));

        player.setPosition(1111, 1111);
        assertFalse(openCraftingComponent.inRange(player.getPosition()));
        assertTrue(openCraftingComponent.getCraftingStatus());
    }
@Test
    void shouldGetCraftingStatus() {
        assertFalse(openCraftingComponent.getCraftingStatus());
    }
    @Test
    void shouldSetCraftingStatus() {
        OpenCraftingComponent.setCraftingStatus();
        assertTrue(openCraftingComponent.getCraftingStatus());
    }
}