This blog is suitable:
* Use eclipse + ADT to develop the coder of the android Project
* The coder that knows and uses build path
* Coder for which you want to write test code
JUnit debugs and tests the Java project. In Android development, it also has its own testing framework.
However, there are not many projects, at least I do!
The following describes a simple and direct debugging method.
1. Create an android Project
It is just a simple Android project, which is easy to explain below.
2. Create a Java Project
3. Right-click the Java Project
4. Select Java build path
5. Add an android Project
Click Add in Step 4, select ondemo, and click OK.
6. Build the test class logictest in the Java Project
Source code
import com.example.ondemo.util.StringUtil;public class LogicTest {public static void main(String[] args) {int res = StringUtil.compare("1", "2");System.out.println("res = " + res);System.out.println("the MainActivity flag = " + com.example.ondemo.MainActivity.FLAG);}}
We can see that the stringutil under the util package is tested.
Methods and mainactivity constants.
Let's test the activity method.
import com.example.ondemo.util.StringUtil;public class LogicTest {public static void main(String[] args) {int res = StringUtil.compare("1", "2");System.out.println("res = " + res);int res2 = com.example.ondemo.MainActivity.getFlag();System.out.println("res2 = " + res2);System.out.println("the MainActivity flag = " + com.example.ondemo.MainActivity.FLAG);}}
When running (as Java application), the program will report an error, mainly because the activity class cannot be found.
Here, you can build path the Android. jar that corresponds to your current Android project SDK.
This android jar package is under the corresponding Android-SDK installation directory platforms.
Build path Android jar, Java project structure
Run again
Note:
If other third-party jar files (such as APACHE) are used in the android project ),
The corresponding build path should also be included in the Java project.