# Cleaning Up Test Files and Resources

DevFeed: [Cleaning Up Test Files and Resources](<https://devfeed.tech/articles/superior-testing-cleaning-up-29376.md>)

Original publisher: [Read original article](<https://arturdryomov.dev/posts/superior-testing-cleaning-up/>)

Author: Artur Dryomov

Published: 2019-06-06T00:00:00Z

Content type: tutorial

Language: en

Sources: [Artur Dryomov](<https://devfeed.tech/sources/artur-dryomov.md>)

Topics: [Testing](<https://devfeed.tech/topics/testing.md>), [Memory Leaks](<https://devfeed.tech/topics/memory-leaks.md>), [Mocking](<https://devfeed.tech/topics/mocking.md>), [Filesystems](<https://devfeed.tech/topics/filesystems.md>), [Java](<https://devfeed.tech/topics/java.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>)

Tags: [files](<https://devfeed.tech/tags/files.md>), [junit](<https://devfeed.tech/tags/junit.md>), [memory-leaks](<https://devfeed.tech/tags/memory-leaks.md>), [mocking](<https://devfeed.tech/tags/mocking.md>), [mockito](<https://devfeed.tech/tags/mockito.md>), [testing](<https://devfeed.tech/tags/testing.md>)

## AI overview

This tutorial explains how cleanup practices can improve tests. It discusses memory leaks and Mockito inline mocking, suggests using stubs that do not track invocations when verification is unnecessary, and recommends creating test files only in temporary directories and deleting them after each run.

## Source excerpt

There is a game called Viscera Cleanup Detail. The task in this game is to... clean things up. Well, it is a bit more exciting since it involves alien invasions, but at the end of the day players become space janitors. It is surprisingly addictive. Cleaning things is useful and helpful in a lot of ways. Developers understand that, but usually there is an additional motivation to keep things in order -- users. Nobody wants a product that breaks because there is not enough memory or wrecks havoc across the file system. The picture is very different with tests -- often they become a second class citizen. It shouldn't be this way.