Xceptance / neodymium-library

A test automation library based on common other best practice open source libraries. It adds missing functionalities but does not reinvent the wheel. Just glues stuff together nicely and adds some sprinkles.
MIT License
80 stars 11 forks source link

Improve temporary file handling in test #180

Open occupant23 opened 3 years ago

occupant23 commented 3 years ago

Current solution: Add a file to a List in NeodymiumTest and the inherited @AfterClass method will delete them after the test.

// create a file 
File file = new File(PATH);
// add it to the list
NeodymiumTest.tempFiles.add(file);

// this function will take care of the rest
@AfterClass
public static void cleanUp()
{
    for (File tempFile : tempFiles)
    {
        deleteTempFile(tempFile);
    }
}

An alternative solution could be to use the appropriate interface of File

File tempConfigFile = new File(PATH);
tempConfigFile.deleteOnExit();
// interact with the file
writeMapToPropertiesFile(properties, tempConfigFile);

Please validate this approach and remove the old approach and all unused functions if this works as expected.