Tag: tdd

针对iPhone Native应用程序的测试驱动设计

我正在试验iPhone SDK并做一些TDD ala Dr. Nic的rbiPhoneTest项目。 我想知道有多少(如果有的话)成功使用这个或任何其他测试框架的iPhone / Cocoa? 更重要的是,我想知道如何最好地断言专有的二进制请求/响应协议。 想法是通过网络发送二进制请求并接收二进制响应。 使用byte和’ing和oring创建请求和响应。 我正在使用黄金副本模式来测试我的请求。 这是我到目前为止所拥有的。 不要笑,因为我是btoh Objective C和Ruby的新手: require File.dirname(__FILE__) + ‘/test_helper’ require ‘fileutils’ require ‘io’ require “MyModel.bundle” OSX::ns_import :MyModel module MyTestExtensions def is_absolute_path(path) return /^\/.*/.match(path) end def parent_directory(file) dir = file if(! is_absolute_path(dir)) dir = File.expand_path(dir) end dir = File.dirname(dir) assert is_absolute_path(dir), “Expecting an absolute path […]

Rspec:期望与预期阻止 – 有什么区别?

刚学习rspec语法,我注意到这段代码有效: context “given a bad list of players” do let(:bad_players) { {} } it “fails to create given a bad player list” do expect{ Team.new(“Random”, bad_players) }.to raise_error end end 但是这段代码没有: context “given a bad list of players” do let(:bad_players) { {} } it “fails to create given a bad player list” do expect( Team.new(“Random”, […]

在测试“无限循环”时,最佳做法是什么?

我的基本逻辑是在某处运行无限循环并尽可能地测试它。 拥有无限循环的原因并不重要(游戏的主循环,类似守护进程的逻辑……)而且我更多地询问有关这种情况的最佳实践。 我们以此代码为例: module Blah extend self def run some_initializer_method loop do some_other_method yet_another_method end end end 我想使用Blah.run测试方法Blah.run (我也使用RR ,但普通的rspec是一个可接受的答案)。 我认为最好的方法是分解更多,比如将循环分成另一种方法或其他方法: module Blah extend self def run some_initializer_method do_some_looping end def do_some_looping loop do some_other_method yet_another_method end end end …这允许我们测试run并模拟循环…但是在某些时候需要测试循环内的代码。 那么在这种情况下你会做什么? 只是不测试这个逻辑,意味着测试some_other_method & yet_another_method但不测试do_some_looping ? 通过模拟在某个时刻让循环中断? ……别的什么?