Priya
Priya

Reputation: 2669

How to write Unit Test Case for singleton class kotlin

I want to release current instance but that not working here is there any easier way to handle it.

I have a class -> DownloadManager which is singleton

And I have a @Before test which always execute unit test case and I am initially this DownloadManager please find below class example.

@Before
fun setup() {
    sut = spyk(DownloadManager()
}

Upvotes: 0

Views: 100

Answers (1)

Akshay
Akshay

Reputation: 71

You should release the instance by using a tearDown() method,

@After
    fun tearDown() {
        sut.close()
    }

It will ensuree that the downloadManager instance is properly closed after the test method, thus avoiding potential resource leaks.

Upvotes: 0

Related Questions