Eyes, JAPAN Blog > Some Thoughts of Testing in Development

Some Thoughts of Testing in Development

will

この記事は1年以上前に書かれたもので、内容が古い可能性がありますのでご注意ください。

These several weeks, we tried to use Kiwi, one of BDD frameworks for iOS development. Since it is the first time to use this framework in the development, we spent a lot of time to get used to it. At the beginning, the progress of development was super slow. To catch up the schedule, we decided to use it after development.

When writing test cases after development, I found that we need to change the structure of method or variables for testing. Give example of class MgtMenuItemTableViewController, there are some private variables and methods. Normally, in the implement file, they can be like:

@interface MgtMenuItemTableViewController ()
{
   NSArray                          *itemCategories;
   NSMutableDictionary              *tableListDict;
   MenuItem                         *selectedItem;
   MgtMenuItemEditingViewController *rightViewController;
}
-(void)reloadTableView;
- (IBAction)editTapped:(id)sender;
- (IBAction)doneEditing:(id)sender;
@end

But during the testing, test cases usually need to access these private variables. It is impossible to access these variables, if the code is written above. It need to be refactored:

@interface MgtMenuItemTableViewController ()
@property(nonatomic, retain)NSArray                          *itemCategories;
@property(nonatomic, retain)NSMutableDictionary              *tableListDict;
@property(nonatomic, retain)MenuItem                         *selectedItem;
@property(nonatomic, retain)MgtMenuItemEditingViewController *rightViewController;

-(void)reloadTableView;
- (IBAction)editTapped:(id)sender;
- (IBAction)doneEditing:(id)sender;
@end

Not only changes in the @interface block, but also the parts, which use the variable, need to use self.[variable_name].
Finally, I found that it spent more time, compared with test first development.

There still are some issues like:
1. It is almost impossible to completely test the software, but can follow the function specification completely. The function specification is the reference of the testing. If the specification change, the test cases should change at the same time.
2. Kiwi is BDD tool, each context in the test case can follow the use case in the specification to make the reference clearly.
3. The test code may be much longer than the application code.

  • このエントリーをはてなブックマークに追加

Comments are closed.