Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Autogenerate unit test stubs on Android studio

I am creating the unit test for some legacy android codes.

Currently i need to manually create the unit test for each class/method in test/java.

Is there an automated way to auto generate all the test stubs? ideally from the Android studio IDE? (similar to how parasoft can autogenerate empty test stubs for C++ classes and methods).

I am using robolectric on Android studio 1.2.1

like image 835
Angel Koh Avatar asked May 08 '15 05:05

Angel Koh


People also ask

How do you stub in unit testing?

To use stubs, you have to write your component so that it uses only interfaces, not classes, to refer to other parts of the application. This is a good design practice because it makes changes in one part less likely to require changes in another. For testing, it allows you to substitute a stub for a real component.

How do I run unit test on Android?

To run all tests in a class or a specific method, open the test file in the Code Editor and do either of the following: Press the Run test icon in the gutter. Right-click on the test class or method and click Run . Select the test class or method and use shortcut Control+Shift+R .

How do you automatically generate unit tests?

To generate unit tests, your types must be public. Open your solution in Visual Studio and then open the class file that has methods you want to test. Right-click on a method and choose Run IntelliTest to generate unit tests for the code in your method. IntelliTest runs your code many times with different inputs.

How do you write JUnit test cases for Android?

You write your local unit test class as a JUnit 4 test class. To do so, create a class that contains one or more test methods, usually in module-name/src/test/ . A test method begins with the @Test annotation and contains the code to exercise and verify a single aspect of the component that you want to test.


1 Answers

Like this: Right-click the class name. Go To -> Test. Select the function, Done.

enter image description here

like image 84
linkaipeng Avatar answered Sep 24 '22 01:09

linkaipeng