在我尝试将BDD库移植到Android JUnit运行器期间,我遇到了如何从测试运行中正确拉回数据的僵局。
我认为我有两个选择:
//reportFile==/data/data/com.packagename.app/cache/jgiven
new ScenarioJsonWriter( model ).write( reportFile );
问题:
如何以稳定和正确的方式执行1.不改变应用程序权限以写入外部存储,或adb vodoo(root,run-as等)
或者如何做2.正确地说,我可以创建一个RunListener,将这些信息记录为raw或logcat,但仍然感觉不对,如何编写一个可以连接的gradle插件这些是原始结果,并在测试执行期间将它们保存到某个文件
public class JGivenTestRunListener extends InstrumentationResultPrinter {
private static final String LOG_TAG = "JGivenTestRunListener";
/**
* This value, if stored with key {@link android.app.Instrumentation#REPORT_KEY_IDENTIFIER},
* identifies AndroidJUnitRunner as the source of the report. This is sent with all
* status messages.
*/
public static final String REPORT_VALUE_ID = "AndroidJUnitRunner";
/**
* Used for sending scenario model json to the instrumentation for further processing
*/
public static final String REPORT_KEY_JGIVEN_SCENARIO_MODEL = "scenariomodel";
Bundle jgivenTestResult;
private final Bundle mJgivenResultTemplate;
public JGivenTestRunListener() {
mJgivenResultTemplate=new Bundle();
}
@Override
public void testRunStarted(Description description) throws Exception {
mJgivenResultTemplate.putString(Instrumentation.REPORT_KEY_IDENTIFIER, REPORT_VALUE_ID);
jgivenTestResult=new Bundle(mJgivenResultTemplate);
super.testRunStarted(description);
}
@Override
public void testFinished(Description description) throws Exception {
ReportModel reportModel = ScenarioModelHolder.getInstance().getAndRemoveReportModel(description.getTestClass());
String reportJson = new ScenarioJsonWriter(reportModel).toString();
Log.e("REPORT",reportJson);
jgivenTestResult.putString(REPORT_KEY_JGIVEN_SCENARIO_MODEL, reportJson);
jgivenTestResult.putString(Instrumentation.REPORT_KEY_STREAMRESULT, "");
sendStatus(0,jgivenTestResult );
super.testFinished(description);
}
}
有任何建议如何解决这个问题?