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

后端 未结 4 2155
别跟我提以往
别跟我提以往 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:59

    Follow the guidelines available here :

    http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Testing

    and here

    http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Configuring-the-Structure

    Summary :

    As the first link says you have to rename your test directory as instrumentTest so Studio can automatically detects the sourceSets for your test project

    or

    Alternate is you can have your tests directory in root(with you main directory) and sources in a manner like tests/java, as the second link says

    instrumenttest.setRoot("tests")
    

    in sourceSets configuration under android tag

    From the document

    Note: setRoot() moves the whole sourceSet (and its sub folders) to a new folder. This moves src/instrumentTest/* to tests/* This is Android specific and will not work on Java sourceSets.

提交回复
热议问题