Adding unit tests to existing Android Studio project

How do I add unit or integration tests to and existing Android Studio project?

I've tried adding folders in Project View as well as creating tests through the context menu (right-click).

I can't get Android Studio to recognize the folder as test folders.

I've also tried:

  • How to get Android Studio to recognize file as source (test)
  • Unit testing in android studio
  • Create unit tests in android studio

I can't get Android Studio to recognize the folder as test folders.

Following below folder structure, you should be able to see all your test cases labeled as "test" when select your Project View as "Android"

|- src
  \-- androidTest // for android instrumentation tests
  \-- main        // your source code
  \-- test        // for unit tests

enter image description here