I'm trying to print something when running Android Local Unit Test, but nothing's happening. What's the matter? How can I fix it?
I consulted some documents on http://developer.android.com, found that Android Local Unit Test just run on my machine's JVM, the android.jar file that is used to run unit tests does not contain any actual code, so Log.d() print nothing. If i wanna print log, how can i do?
Here is my code, FeedbackModelTest.java located in src/test/main directory.
package com.upward.reader.mvp.model; import android.util.Log; import com.upward.reader.mvp.bean.FeedbackBean; import com.upward.reader.net.RequestJSONCallback; import org.junit.Test; import java.io.IOException; import java.util.HashMap; import java.util.Map; public class FeedbackModelTest { @Test public void postFeedback() throws Exception { final String url = "http://test.guguread.com/interface/app/user/feedback?"; Map<String, String> params = new HashMap<>(); params.put("content", "content"); new FeedbackModel().postFeedback(url, params, new RequestJSONCallback<FeedbackBean>() { @Override public void onResponse(FeedbackBean result) throws IOException { Log.d("TAG", result.toString()); } @Override public void onFailure(Exception e) { e.printStackTrace(); } }); }
}
Go to the File option > click on “INVALIDATE CACHES/RESTART” then a dialog box will pop up, Select the “INVALIDATE CACHES/RESTART” button. This will automatically restart and build the index of android studio.
@sepehr It's relevant insofar as DTOs are not usually unit-tested because there is no behavior to test. DTOs don't have behavior because behavior isn't serializable, which is specifically the point of DTOs. So it's very common to hear and read that DTOs don't need testing.
The Log. v() method is used to log verbose messages. The Log. d() method is used to log debug messages.
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 .
You should use standard output, System.out.println("Hello StackOverflow")
intead of Log.x()
. Then you can see the log info in the run tab.
2017/12/16 Update: If you can't see the output on the Run
tab, go to Android Monitor
tab to find the output instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With