vendredi 27 février 2015

Use same junit temporary folder for multiple unit tests

In my test class I use junit's temp folder. Then I create a new pdf file in this folder, write to this file and make my assertions. My unit test looks like:



@Test
public void testGeneratePdfIntegration1() throws Exception {

InputStream isMxml = SuperBarcodeProcTest.class.getResourceAsStream(RES_MXML_JOB_1);
InputStream isThumb = SuperBarcodeProcTest.class.getResourceAsStream(RES_PNG_JOB_1);
InputStream isPpf = SuperBarcodeProcTest.class.getResourceAsStream(RES_PPF_JOB_1);

Path destination = tempFolder.newFile("target1.pdf").toPath();

superBarcodeProc = new SuperBarcodeProc(isThumb, isMxml, isPpf, destination.toString());
superBarcodeProc.setDescription("Bogen: 18163407_01_B04_ST_135gl_1000_1-1");
superBarcodeProc.setBarcode("18163407_01");
superBarcodeProc.generatePdf();

assertTrue(Files.exists(destination));
assertTrue(Files.size(destination) > 1024);
}


After the test ends, the temp folder is being deleted. The problem is that I have multiple unit tests which generate pdf file with different settings in the same temp folder like the test in the code I've provided and when I run all tests in the class only the first one successes. My guess is that after the first test ends the temp folder is gone and the other tests fail with the IOException saying that the system cannot find the given path. The question is how can I use the same folder for multiple unit tests without the folder being deleted or is this impossible and I have to create a temp folder for each test case?


Aucun commentaire:

Enregistrer un commentaire