7

I have a question about testing some Android code. I'm currently making some JSON to Object converting code and it's very annoying to keep going into the emulator and seeing if it works.

I'm curious if there is a way to do this faster, for example without running the emulator?

Thanks in advance.

4
  • you could always use an actual android device. this is my preferred testing method. could take a while to build if you have a low core processor computer/laptop Commented Feb 24, 2016 at 20:16
  • jUnit developer.android.com/training/testing/start/index.html Commented Feb 24, 2016 at 20:16
  • 1
    Isn't JUnit meant for testing when a method is finished? I'm looking for a quick way to try if my code works. Commented Feb 24, 2016 at 20:22
  • 1
    @me from the past, please use Test Driven Development :-D Commented Jan 11, 2021 at 13:55

5 Answers 5

5

Now with Kotlin, it is possible to quickly execute some piece of code without running in emulator or device.

Suppose you have a class like this

class MyTestClass() {
    init {
        println("This is from Init")
    }
}

you can quickly run this by creating a main function on top and running it.

fun main(){
    val myClass = MyTestClass()
}

class MyTestClass() {
    init {
        println("This is from Init")
    }
}
Sign up to request clarification or add additional context in comments.

Comments

3

This is impossible, but if you want to gain more time, use the genymotion emulator is faster then the Android Studio emulator.

https://www.genymotion.com

2 Comments

It also supports a lot more (i.e Google Play Services)
This sounds like a viable option. I'll also look into the debugging on my phone. Thanks for the answers.
1

You should be able to run/test your code directly on your laptop or PC by calling your code inside test folder,

You just want to test the data result of JSON or corresponding object(s), in this case you can just get the result directly on your laptop and there is no need to run any emulators, for these kinds of tests there is "Unit test" which helps you to run your code and check the results, and this is the fastest way you to run without emulator.

Comments

0

Plug in an android phone, turn on debugging mode in developer options. Way faster to upload test apks and faster, especially if you have a slower pc.

Comments

0

Suppose you are working in TestActivity.java file . Make your TestActivity.java class as Launcher in manifest file. If your class takes some inputs from previous activity then hardcode those inputs as "Strings" . its not the best of the best solution but it can save a lot of your time by directly going to the point you want to go.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.