AY2425S1-CS2113-T10-3 / tp

https://ay2425s1-cs2113-t10-3.github.io/tp/
0 stars 4 forks source link

JUnit tests are modifying local copy of catalog.json #55

Open xenthm opened 1 day ago

xenthm commented 1 day ago

Issue

When gradlew build is run to build the project with Gradle, JUnit tests are run. The JUnit tests for commands that modify the authorList (and hence will save the changes to the data file) are using the local copy of catalog.json to perform tests. This overrides the contents of the file.

Potential fixes

  1. Set up dataFile in Storage to be a different path before running any JUnit test for commands that modify the authorList
  2. Change the implementation of Storage to instantiate it differently for JUnit tests

Contents of catalog.json after gradlew build is run

The authorList serialized here is from a JUnit test. image

averageandyyy commented 1 day ago

Possible to read/load from one file but write the save file to another destination to prevent the overwriting? Just an idea.

xenthm commented 1 day ago

Possible to read/load from one file but write the save file to another destination to prevent the overwriting? Just an idea.

Do you mean just for tests? Because if we do this for the main app we need to get the user to indicate where they last saved their data.

  1. Set up dataFile in Storage to be a different path before running any JUnit test for commands that modify the authorList

Actually, option 1 is already implemented, but only in StorageTest.

image

So all we need to do it extend it so that all tests do this.

averageandyyy commented 1 day ago

yup just for tests only, basically like the IO test where we have actual and expected as two separate files.

xenthm commented 1 day ago

Alright, I did that for StorageTest. For future development it is probably worth it to set a global JUnit setting so that all tests use a different data file. However, it needs to be deconflicted with testCatalog.json which is needed by StorageTest. It shouldn't be changed.

xenthm commented 1 day ago

Updated severity as this only affects developers that use gradlew build.