AdvancedPeripherals icon indicating copy to clipboard operation
AdvancedPeripherals copied to clipboard

Add game and junit tests to AP

Open SirEndii opened this issue 1 year ago • 8 comments

This PR aims to add the long needed game tests to AP. It's still a draft. We will use the Testing Framework from CC to accomplish this The framework is implemented, and I started to work on the first tests

  • Checklist
  • [ ] - Add JUnit tests for common AP functions
  • [ ] - Mod Integrations
      • [x] - Botania
      • [x] - AE 2
      • [x] - Note Blocks
      • [x] - Beacons
      • [ ] - RS (currently not possible)
      • [ ] - Create
      • [ ] - Mekanism
      • [ ] - Powah
      • [ ] - Minecolonies (currently not possible)
  • [ ] - Peripherals
      • [ ] - Environment Detector
      • [x] - Chat Box
      • [ ] - Player Detector
      • [x] - Energy Detector
      • [ ] - Inventory Manager
      • [x] - Redstone Integrator
      • [x] - Block Reader
      • [x] - Geo Scanner
      • [x] - NBT Storage
  • [ ] - Turtles
      • [ ] - Chatty
      • [ ] - Chunky (Not possible to test)
      • [ ] - Compass
      • [ ] - Player Detector
      • [ ] - Environment Detector
      • [ ] - Geo
      • [ ] - Weak Automata
      • [ ] - OP Weak Automata
      • [ ] - Husbandry Automata
      • [ ] - OP Husbandry Automata
      • [ ] - End Automata
      • [ ] - OP End Automata
  • [ ] - Pocket Computers (?) Currently not possible without an entity that loads the pocket
      • [ ] - Chatty
      • [ ] - Player Detector
      • [ ] - Enviroment
      • [ ] - Geo
  • [x] - Documentation

ToDos:

  • [ ] The Geo Scanner docs list a getScanCooldown method which currently does not exist in AP, so I cannot test it (the test currently uses the "internal" getOperationCooldown("scanBlocks") method)
  • [x] The isOnEnchantedSoil function on Botania Mana Flowers always returns false, even when the flower is placed on enchanted soil. This seems to be the case because the overgrowth variable on a Mana Flower is only set to true during the flower tick (see https://github.com/VazkiiMods/Botania/blob/1.20.x/Xplat/src/main/java/vazkii/botania/api/block_entity/SpecialFlowerBlockEntity.java#L100)
  • [ ] The isEmpty method on Botania Mana Pools is currently missing
  • [ ] For the Botania Mod Integration, some methods are only available in the 1.20.1 versions of AP, so they're currently commented out in the .lua test files. When merging this to the 1.20.1 branch, these methods should be uncommented
  • [ ] Botania Mana Spreaders have a getBounding method returning the coordinates of the block that the spreader is directed towards, shouldn't it be called getBinding then?
  • [ ] The isEmpty function on Botania Mana Spreaders does not return if the mana in the spreader is empty but if the item handler of the spreader is empty
  • [ ] On Note Blocks, the method changeNoteBy is named somewhat weird. It sets the note value to the given parameter and does not change the note by x amount. Shouldn't it be called setNote or something?

SirEndii avatar Feb 23 '24 22:02 SirEndii

I will mark this as high priority. I will work on this asap since we really need tests for AP

SirEndii avatar Apr 30 '24 20:04 SirEndii

I've implemented (copied) the needed stuff from the test source sets, but there is currently another issue with hamcrest and junit I need to work on I'm going to fix this asap. For now there are the cc tests in AP for testing purposes

SirEndii avatar May 02 '24 21:05 SirEndii

I fixed everything that need to be fixed (I think) The game tests are now ready to be created

SirEndii avatar May 03 '24 00:05 SirEndii

We're on a good run. I've added the first game tests using an ingame script. I will see if I can run the functions via the kotlin script like CC does it with the APIs like turtle.*. But I doubt that this is easily possible with peripherals

We just now need to add the game tests itself. I will also write a documentation for that

SirEndii avatar May 05 '24 21:05 SirEndii

Had another error in my thinking. gradle build already executes test and runGameTestServer, I'll change it later

SirEndii avatar May 05 '24 21:05 SirEndii

I think there is nothing left to do in terms of the framework. Now we just need to create the tests. There is a me bridge tests to test something a bit more complex and the environment detector which currently just tests one function.

I've created a documentation markdown file located in docs/CREATING_TESTS.md. It explains the basics, how to run and write tests. But it needs some more love with examples and code. If someone wants to create tests, feel free to do so😅 Would speed things up For non collaborators, you could create a PR which targets the feat/tests branch. But I am not too sure how well this goes

SirEndii avatar May 07 '24 19:05 SirEndii