How to get Android Studio to recognize file as source (test)

后端 未结 4 2154
别跟我提以往
别跟我提以往 2020-12-05 04:22

I\'m trying to create Robolectric tests for an android project (heck, i\'d be happy to even make them unit tests)

I have the folder directory as:

MyA         


        
4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-05 04:57

    In Android Studio 1.0 the scheme has changed a little bit.

    Your path should be (app)/src/androidTest/java/com/myapp/HelloWorldTest.java

    Here's how I set up Unit Tests in a new Android Studio project:

    • Open app in Android Studio.
    • Set the Project explorer (left hand window) to display 'Project' mode. Tap the little drop-down at the top left and select 'Project'.
    • Right click the 'src' directory, 'New -> Directory'.
    • Call new directory androidTest
    • Right click androidTest and add a 'java' directory. It will appear in green (indicating it's a test src directory).
    • Now right-click again and add a package, e.g. com.mycompany.myapp.tests
    • Add a new class that extends AndroidTestCase.

    Now add a new configuration for testing:

    • Edit Configurations
    • Click + at top left
    • Select Android Tests
    • In General Tab select your main module.
    • Hit OK

    Now you can run the tests.

提交回复
热议问题