Details

Recommendation type: Files created

Configurable: Yes

Filter category: Unstable test environment

Description

Tests should not have side effects on the test environment. Failing to delete files created on the file system can cause subsequent test runs or other tests to fail. Created files should be removed by the time the test has completed.

Example

In the following example, the created files are removed after the test is executed. Failing to remove the files will generate this recommendation.

public class MyTest {
	@Before
	public void setUp() {
		// Prepare test environment
		_testFile = new File(path);
	}
	@After
	public void tearDown() {
		// Remove test related files
		_testFile.delete();
	}
}
  • No labels