Tyl*_*ier 46 java android maven-2 roboguice robolectric
我正在使用Robolectric来测试Android.我正在通过maven运行我的测试,例如
mvn -Dtest=LogTest test
如果我有代码写入日志,例如
Log.d("TAG", "blah");
或者使用Roboguice的 Ln
Ln.d("blah");
我没有在maven的surefire日志(文本文件)中看到任何输出.
理想情况下,我实际上想要简单的日志语句转到控制台.我可以使用写入控制台System.out.println("blah"),但当然我宁愿使用支持的日志API.
所以我的问题是,为什么我根本看不到日志输出,如何将日志消息写入控制台?
Jes*_*ido 71
我正在运行robolectric-2.0-alpha-3.
对我有用的是在我的测试的setUp方法中设置流到stdout
就像是:
@Before
public void setUp() throws Exception {
  ShadowLog.stream = System.out;
  //you other setup here
}
使用这个版本的robolectric,我ShadowLog.stream = System.out在自定义的TestRunner或TestLifeycleApplication中没有成功地做同样的事情.
设置系统属性System.setProperty("robolectric.logging","stdout");也没有任何效果,但它可能适用于以前的版本.
小智 14
我使用robolectric 2.3.对我有用:
进入我的@Before:
ShadowLog.stream = System.out;
在我的测试函数中,我可以使用(ShadowLog.有其他选项):
ShadowLog.v("tag", "message");
在我测试的类中,我可以在日志中添加一些消息:
System.out.println("message");
Edw*_*ale 11
默认情况下,使用RobolectricTestRunner时的日志输出消失.您可以通过查看该类的setupLogging()方法来配置它的位置.
总之,您需要将设置robolectric.logging系统属性要么stdout,stderr或在日志中应写入的文件路径.我在RobolectricTestRunner我用于所有测试的子类的构造函数中执行此操作,以便始终将日志写入stdout.
在测试运行之前将以下内容添加到测试设置中:
ShadowLog.stream = System.out;
Robolectric.bindShadowClass(ShadowLog.class);
https://groups.google.com/forum/?fromgroups=#!msg/robolectric/PK-9cQQQROw/svuQzM5h_vsJ
| 归档时间: | 
 | 
| 查看次数: | 12350 次 | 
| 最近记录: |