0

In iOS there exists a tear block you can add to individual tests called addTearDownBlock and you put it inside a single test and it will only execute for that single test.

Does android have a similar version of this?

BlondeSwan
  • 772
  • 5
  • 26

1 Answers1

0

Unit testing in android is done with xUnit variation known as JUnit. If you are using JUnit 4.0, then use the following annotation:

@AfterClass //Will only execute once after all the tests in the class have exhausted

@After //Will run after every test

If you are using JUnit 5.0 then use the following annotation:

@AfterEach //Will run after every test

@AfterAll //Will only execute once after all the tests in the class have exhausted
Karan Dhillon
  • 1,186
  • 1
  • 6
  • 14
  • But does there exist one for a single function in a class? I would like one so that I can run a tear down on this one function in the case it fails but I still need to tear something down. Right now if it fails it stops executing and there are tear down steps I would like to execute for only this test – BlondeSwan Apr 24 '20 at 17:53