If I have a project in Eclipse, I can at any time create a class with a main
and test anything having all the classes and libraries of my project available.
How do I do something like that in Android Studio?
If I have a big project and I would like to test a small method in isolation, how would I do that without needing to run the emulator or an Activity, etc?
To create a run/debug configuration for a class or method in your Java code, follow these steps:
- Open a project in Android or Project view.
- Open a Java file in the Code Editor.
- Select a class or method in the code, and then press Ctrl+Shift+T (⌘⇧T).
- Select Create New Test from the menu that appears.
- In the Create Test dialog, optionally change the field values, and then click OK.
- In the Choose Destination Directory dialog, select androidTest to create an instrumented test or test to create a local unit test. Click OK.
The new test appears in the Project window in the corresponding test source set.
- To run the test, do one of the following:
- In the Project window, right-click the test and select Run or Debug.
- In the Code Editor, right-click a class definition in the test file and select Run or Debug to test all methods in the class.
- In the Code Editor, right-click a method name in the test file and select Run or Debug to test just that method.
- In the Code Editor, click Play in the left margin next to a class or method and select Run or Debug.
- To save the configuration, select Save from the Select Run/Debug Configuration drop-down list within the toolbar.
The drop-down list is to the left of Run and Debug ; for example, .
Alternatively, right-click the item again and select Save.
Or, select the configuration in the Run/Debug Configurations dialog and click Save Configuration on the upper lef
SOURCE
Just right click on your class and select Run YourClassName.main()