Heckle
테스트를 테스트한다 - 루비 세디즘
"RSpec/Test::Unit is your safety belt. RCov is your airbag. Heckle is your helmet, neck brace and full fireproof suit."
"루비 프로그래밍을 하는데 RSpec이 안전벨트, RCov를 에어백이라고 한다면, Heckle은 헬멧과 목 보호대, 완벽한 방화복입니다." -- Aslak Hellesoy
Heckle은 Ruby2Ruby와 ParseTree를 이용해 루비 코드를 바꿉니다. 그렇다면, 테스트는 반드시 실패해야합니다. 만일 테스트가 성공한다면, 그 테스트에는 '빈틈'이 있는 것입니다. 이런 식의 코드 변형을 통한 테스트는 루비 코드를 특히나 테스트를 더욱 견고하게 해줍니다.
구구단 예제
- gugu_spec.rb
- context "구구단" do
specify "5단을 잘 출력한다" do
5.dan.to_a.should_be_eql [5,10,15,20,25,30,35,40,45]
end
end
- gugu.rb
- class Fixnum
def dan
raise if self < 2 || self > 9
(1..9).map{|i| self*i}
end
end
실행 결과:
- [deepblue:ruby/test/heckle] deepblue% spec gugu_spec.rb --heckle Fixnum.dan . Finished in 0.000549 seconds 1 specification, 0 failures **********************************************************************
*** Fixnum#dan loaded with 4 possible mutations
********************************************************************** 4 mutations remaining...
3 mutations remaining...
2 mutations remaining...
1 mutations remaining... The following mutations didn't cause test failures: def dan
raise if ((self < -5) or (self > 9))
(1..9).map do |i|
(self * i)
end
end def dan
raise if ((self < 2) or (self > 14))
(1..9).map do |i|
(self * i)
end
end
테스트가 부족함을 알 수 있다. 테스트를 보강하자.
- context "구구단" do
specify "5단을 잘 출력한다" do
5.dan.to_a.should_be_eql [5,10,15,20,25,30,35,40,45]
end
specify "우리나라 구구단은 2단부터 9단까지뿐이다" do
lambda{ 1.dan }.should_raise
lambda{ 10.dan }.should_raise
end
end
- [deepblue:ruby/test/heckle] deepblue% spec gugu_spec.rb --heckle Fixnum.dan .. Finished in 0.000841 seconds 2 specifications, 0 failures **********************************************************************
*** Fixnum#dan loaded with 4 possible mutations
********************************************************************** 4 mutations remaining...
3 mutations remaining...
2 mutations remaining...
1 mutations remaining... The following mutations didn't cause test failures: def dan
raise if ((self < 2) or (self > 6))
(1..9).map do |i|
(self * i)
end
end
아직도 부족하다
- context "구구단" do
specify "5단을 잘 출력한다" do
5.dan.to_a.should_be_eql [5,10,15,20,25,30,35,40,45]
end
specify "우리나라 구구단은 2단부터 9단까지뿐이다" do
lambda{ 1.dan }.should_raise
lambda{ 10.dan }.should_raise (2..9).each do |i|
lambda{ i.dan }.should_not_raise
end
end
end
- [deepblue:ruby/test/heckle] deepblue% spec gugu_spec.rb --heckle Fixnum.dan .. Finished in 0.000974 seconds 2 specifications, 0 failures **********************************************************************
*** Fixnum#dan loaded with 4 possible mutations
********************************************************************** 4 mutations remaining...
3 mutations remaining...
2 mutations remaining...
1 mutations remaining...
No mutants survived. Cool!
드디어 성공했다!
참고 자료
History
Last edited on 11/22/2007 01:04 by deepblue
Comments (0)