I have an @Test method with invocationCount=3.
Each time this method is run, there is a call for preparing some doc into another method.
All it’s working GREAT when the @Test is run for the 1st time.
The doc is succesfully found and loaded:
final DocumentRegistryResource documentRegistryResource =
RestClientFactory.getInstance().createDocumentRegistryResource(
getUserRestAuth());
final File importFile = new File(
this.getClass().getResource("/documents-template-test.xml").getFile());
BUT, at the 2nd and 3rd invocation, i receive a null exception:
this.getClass().getResource("/documents-template-test.xml")
is no longer found.
Can anyone explain me WHY? The original file is on the same place, nothing was moved
during the 1st time invocation…
Do you close your file in the cleanup phase? Otherwise, your file might be locked on the second invocation of your test.
Also, be careful with the use of the
finalkeyword combined with a test case. Usingstaticorfinalcan break a correct initialization or cleanup.