2012-08-31 26 views
0

我需要一些建议和指导相关的Android应用程序TDD的Android应用程序

我正在开发一个复杂的Android应用程序(一种自动化的机器人播放器的网页游戏)TDD。现在我有一个试点,在开始之前继续它的发展,我想为它做完整的TDD。

该应用的主要目的是运行作为与HTTP服务器进行通信的后台服务 - 这将发送HTTP请求使用JSON内容

它有两种模式运行:

- service mode - it will run in background- read some data configuration from database and communicate with the server 
- GUI mode - communication with server on demand + configuration for running in service mode. 

GUI层被设计为MVP,所以在一个模块(一个MVP单元)中完成的所有业务都与视图分离,因此,所有应用逻辑都是“不依赖于Android”。

我有我需要做单元测试的几大层次:

- domain data access : 
     database storage (ormlite) 
     android specific storage - shared prefs.., 
     files 
- server communication - http client (spring android rest template) 
         http content conversion (gson) 

- background services - android services 
- GUI - activities 
- app business - android independent - algorithms, computations, ... 

总之需要TDD - 为每一个这些层的独立,而且还集成测试的完整流程。

测试包括:

- database DAO tests 
    - http client requests 
    - GSON conversion TDDs 
    - business logic - simple tests for methods 
    - unit testsfor running and scheduled background services 
    - activity unit testing 
    - test suites (service + DAO + json conversion + http requests) 

我的第一个问题是什么TDD框架将是最适合我的需要?我应该用嘲笑吗?

请给我一些方向去。谢谢

回答

2

首先,对于自动测试:junit


对于流利的断言,你可以看看fest-assertions。他们提供了很多例子,here。但享受这一个String

assertThat("Frodo").startsWith("Fro").endsWith("do").hasSize(5); 

这不仅是和谐,它也增加了你的生产力。


既然你想写单元测试,你将不得不编写mock对象。当然,你可以在没有任何框架的情况下完成它,但它很tedious

Personnaly,我是Mockito的粉丝。这是一个伟大的,非常流利的API。另外,你可以用BDDMockito静态方法以BDD的方式写测试。看:

//given 
given(seller.askForBread()).willReturn(new Bread()); 
//when 
Goods goods = shop.buyBread(); 
//then 
assertThat(goods, containBread()); 

有时你会依赖于类,你不能嘲笑,例如final classBluetoothAdapter。在这些情况下(并且只在这些情况下),您可以使用PowerMock

看也是在这个东东:

还有一本书:Android Application Testing Guide