【发布时间】:2012-02-29 16:43:56
【问题描述】:
我的项目设置
-
库项目 A 包含这样的 fooJSONParser:
public class fooJsonParser { ... // Constructor using the input-stream public DPNodeJsonParser(InputStream inputJsonStream) { // Constructor } /** * Method that has to be executed once the class is instantiated to parse */ public parsedObject parseObj() { // Parses and prints the info } 应用程序项目 B,它使用 库项目 A
问题
现在我创建了一个测试项目tester 来测试App 项目B 并添加一个测试用例来测试fooJsonParser 类。每次有新的 json 数据时,我都会更新 parse 方法并希望使用 tester 项目对其进行测试,并查看解析器是否正确解析,而不是安装、运行应用程序并导航到将使用新的 json 数据。为此,我在 tester 的 assets 文件夹中有一个 json 文件。但我不确定如何读取 json 文件。我认为这与MockContext 有关,但不确定如何使用它,因为documentation 表示所有方法都不起作用。
有人可以建议一个解决方案/提供一个示例来从plain java object test case 读取资产文件吗?
我对 android 测试环境还很陌生。如果有任何不清楚的地方,请告诉我。我可以添加更多信息。
【问题讨论】:
-
我也有类似的问题。您的资产是在
App Project B的资产文件夹中还是在tester的资产文件夹中?
标签: android unit-testing junit