TableFixture
TableFixture 는 FitNesse package의 additional class 입니다. (core FIT fixture set 에는 존재하지 않는 겁니다. FitNesse와 같은 라이브러리의 한 부분으로서 다뤄지고 있습니다.). 반복적인 구조를 가지고 있지 않은 free-form table들을 실행시킬 때 사용합니다.
Table Format
TableFixture로 어떤 포맷인지 어떤 셀을 테스트할 것이지 등을 정하실 수 있습니다. 제한점이 있다면 첫번째 줄은 fixture의 클래스 이름이어야 한다는 것 뿐입니다. 나머지는 여러분 마음대로 하셔도 됩니다. 기존의 인보이스나 reports 혹은 document들을 FitNesse test로 바꿀 때 사용하실 수 있습니다. 아래 예제들은 Test Driven .NET Development with FitNesse 에서 가져온 것입니다. 인보이스를 세금계산으로 verify 하겠습니다.
!|TableFixtureTest| |Item|Product code|Price| |Pragmatic Programmer|B978-0201616224|34.03| |Sony RDR-GX330|ERDR-GX330|94.80| |Test Driven Development By Example|B978-0321146533|32.39| |Net Total||161.22| |Tax (10% on applicable items)||9.48| |Total||170.70|
Fixture class
이 fixture class를 사용하려면 fitnesse.fixtures를 extend 해야 합니다. doStaticTable(int rows) method를 override 합니다. 그 메소드에서 getText(row, column)으로 관계된 cell들의 내용들을 추려내서 table을 process 하는 겁니다. test cell들을 right(row,column)로 correct 하거나 wrong(row,column,actualValue)로 incorrect 하도록 test cell들을 mark 하실 수 있습니다.
아래 예제는 아래에서부터 두번째 줄의 세번째 cell에 있는 값고 매치되는 인보이스로부터 total tax를 verify 하는 에제입니다.
Java Source Code
package info.fitnesse.fixturegallery; import info.fitnesse.fixturegallery.domain.TaxCalculator; import fitnesse.fixtures.TableFixture; public class TableFixtureTest extends TableFixture{ protected void doStaticTable(int rows) { TaxCalculator tc=new TaxCalculator(); double totaltax = 0; for (int row = 1; row < rows - 3; row++) { totaltax += tc.GetTax(getText(row, 1), Double.parseDouble(getText(row, 2))); } double taxintable = Double.parseDouble(getText(rows - 2, 2)); if (taxintable == totaltax) right(rows - 2, 2); else wrong(rows - 2, 2,String.valueOf(totaltax)); } }
.NET Source Code
using System; using System.Collections.Generic; using System.Text; namespace info.fitnesse.fixturegallery { public class TableFixtureTest : global::fitnesse.fixtures.TableFixture { protected override void DoStaticTable(int rows) { TaxCalculator tc = new TaxCalculator(); decimal totaltax = 0; for (int row = 1; row < rows - 3; row++) { totaltax += tc.GetTax(GetString(row, 1), Decimal.Parse(GetString(row, 2))); } decimal taxintable = Decimal.Parse(GetString(rows - 2, 2)); if (taxintable == totaltax) Right(rows - 2, 2); else Wrong(rows - 2, 2, totaltax.ToString()); } } }
Python Source Code
from info.fitnesse.fixturegallery.domain.TaxCalculator import TaxCalculator from fitnesse.fixtures.TableFixture import TableFixture class TableFixtureTest(TableFixture): def doStaticTable(self, rows): tc = TaxCalculator() totalTax = 0.0 for row in range(1, rows - 3): totalTax += tc.getTax(self.getText(row, 1), float(self.getText(row, 2))) taxinTable = float(self.getText(rows - 2, 2)) if taxinTable == totalTax: self.right(self.getCell(rows - 2, 2)) else: self.wrong(self.getCell(rows - 2, 2), str(totalTax))
Notes
정수형으로 변환된 cell 값을 retrieve 할 때 getInt 를 사용하시면 됩니다.
Usage
다른 fixture type으로는 구현하기 힘든 특정 business-specific table 포맷에 대해서 테스트 하기를 원하신다면 이 TableFixture를 사용하시는게 좋습니다. HTML table로 export 될 수 있는 문서를 가지고 있다면 더 쉽게 테스트를 구현하실 수 잇습니다. 그 HTML을 FitNesse로 곧바로 붙여넣기 하면 될 테니까요.
'TDD Project' 카테고리의 다른 글
SequenceFixture Tutorial - FitLibrary - (0) | 2013.08.21 |
---|---|
DoFixture Tutorial - FitLibrary - (0) | 2013.08.17 |
CalculateFixture Tutorials - FitLibrary - (0) | 2013.08.17 |
SetUpFixture tutorial -FitLibrary- (0) | 2013.08.17 |
Import Fixture Tutorial & Summery (FitNesse) (0) | 2013.08.17 |
RowFixture Tutorial (Fitnesse) (0) | 2013.08.14 |
ActionFixture Tutorial (Fitnesse) (0) | 2013.08.14 |
ColumnFixture Tutorial (Fitnesse) (0) | 2013.08.12 |
Spring Framework에서 jUnit 테스트 만들기 - Mockito 를 중심으로 - (0) | 2013.08.11 |
Fitnesse 사용법 간단 정리 (0) | 2013.08.07 |