为什么运行Android Local Unit Test时Log.d()什么都不打印? [英] Why Log.d() print nothing when running Android Local Unit Test?

查看:387
本文介绍了为什么运行Android Local Unit Test时Log.d()什么都不打印?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行 Android本地单元测试时打印某些内容,但没有任何反应.怎么了?我该如何解决?

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?

我在 http://developer.android.com 上查阅了一些文档,发现Android Local Unit Test只是在我的机器的JVM上运行时,用于运行单元测试的android.jar文件不包含任何实际代码,因此Log.d()不输出任何内容.如果我想打印日志,该怎么办?

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?

这是我的代码,位于 src/test/main 目录中的 FeedbackModelTest.java .

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();
        }

    });
}

}

推荐答案

您应该使用标准输出,即Log.x()System.out.println("Hello StackOverflow") intead.然后,您可以在运行选项卡中查看日志信息.

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更新:如果在Run选项卡上看不到输出,请转至Android Monitor选项卡以查找输出.

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.

这篇关于为什么运行Android Local Unit Test时Log.d()什么都不打印?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆