I've been learning test-driven development recently. Test-driven development is a method of extreme programming. It advocates writing test code according to requirements before writing real code (of course, this test code is impossible to pass), and then writing formal code based on the test code. The code written is to make the test code pass step by step. If test-driven development can also be used in Android development, it will greatly speed up our development. But we all know that Android's unit testing is really a headache. Each of its tests requires running on a real device or simulator, which will greatly slow down our testing speed. Robolectric is an Android unit testing framework. The charm of this framework is that it allows your Android code to run on the jvm (not the Android virtual machine), which means that when you do unit testing, you don't need to install your apk on the machine to run it, which will greatly reduce our testing time. (Wouldn't it be nice to run your Android tests directly from inside your IDE?) robolectric official website I encountered many difficulties in the process of building robolectric, and the solutions on the Internet were relatively limited, so I had to explore it myself. Today I will record the construction of the robolectric environment here. 1. Development environment android-studio 2. Required jar package, download address 3. After importing the jar package, you need to modify the project configuration: There is a build variant in the lower left corner of Android studio. Click it and change the test artifact to Unit tests. 4. Write test code:
Note the annotations on the test class here 5. Run this unit test method. When it runs, it may download some things. After it finishes downloading, it will be executed like a normal junit. |
<<: Why I don't like working at a mainstream tech company
>>: Which Google products have more than 1 billion users?
The Internet wave has swept in, bringing populari...
Have you ever tried to go to the toilet at 120 ki...
Winter has gone and spring has arrived. Under the...
People in the south are thinner than people in th...
Apple officially released the iOS15.5beta1 test v...
Feng Shui, which originated in ancient times, is ...
The most popular video gameplay in Taobao store g...
Image source: Tuchong Creative There are many dif...
As the largest audio platform in China, Himalaya ...
Review of this article: Pa Lizhe, chief physician...
This article was reviewed by: Xiaobo Zhou, Doctor...
In 2022, the serious scientific community brought...
At the beginning of the new year, China's new...
BI Intelligence lists Waymo, General Motors, Ford...
How to increase the popularity of Douyin live str...