반응형
블로그 이미지
개발자로서 현장에서 일하면서 새로 접하는 기술들이나 알게된 정보 등을 정리하기 위한 블로그입니다. 운 좋게 미국에서 큰 회사들의 프로젝트에서 컬설턴트로 일하고 있어서 새로운 기술들을 접할 기회가 많이 있습니다. 미국의 IT 프로젝트에서 사용되는 툴들에 대해 많은 분들과 정보를 공유하고 싶습니다.
솔웅

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

글 보관함

카테고리

DoFixture Tutorial - FitLibrary -

2013. 8. 17. 00:36 | Posted by 솔웅


반응형

DoFixture



DoFixture는 story-like test에 사용됩니다. ActionFixture 대신에 이 Fixture를 사용하실 수도 있습니다. 또한 ActionFixture에는 없는 다양한 기능들이 제공됩니다. flow-mode coordination이나 wrapping domain object 같은 것들이 그 예입니다.




Table Format

첫번째 줄은 fixture class 이름입니다. 그 이후의 모든 줄들은 verification을 실행하거나 fixture class의 메소드를 실행시킴으로서 어떤 일을 진행하도록 합니다. 메소드 이름은 그 줄의 홀수번째 cell들을 join 해서 만들어 집니다. argument 값들은 짝수번째 cell 들에서 가져오게 됩니다.

마약 메소드가 boolean 값을 반환한다면 그 줄은 테스트해야할 줄로 간주되고 FALSE를 반환하면 test fail로 간주 됩니다. 메소드가 void 거나 boolean 값 이외의 값을 반환하면 예외가 발생하지 않으면 그 메소드를 그대로 실행하게 됩니다.

!|DoFixtureTest|
|fill|10|times with|x|
|char at|4|is|x|
|set list|A,B,C,D|
|char at|2|is|C|




Fixture class

이 fixture를 사용하려면 fitlibrary.DoFixture를 extend 합니다. 모든 verification과 action들에 대해 public method를 정의합니다. 메소드 이름은 홀수번째에서 argument들은 짝수번째에서 가져 옵니다. 곧바로 메소드 이름을 타입할 필요는 없습니다. 테이블을 먼저 작성하고 그 다음에 테스트를 돌리세요. 처음에는 fail 하게 될 겁니다. 여기서 메소드 이름을 카피하시면 됩니다.

Java Source Code

package info.fitnesse.fixturegallery;
import java.util.Arrays;
import fitlibrary.DoFixture;

public class DoFixtureTest extends DoFixture {
	public String letters;
	public void fillTimesWith(int count,char c){
		char[] arr=new char[count];
		Arrays.fill(arr,c);
		letters=new String(arr);
	}
	public boolean charAtIs(int position, char c){
		return letters.charAt(position)==c;
	}
	public void setList(char[] array){
		letters=new String(array);
	}
	public char charAt(int position){
		return letters.charAt(position);
	}
}

.NET Source Code

using System;
using System.Collections.Generic;
using System.Text;

namespace info.fitnesse.fixturegallery
{
    public class DoFixtureTest : fitlibrary.DoFixture
    {
        private String contents;
        public void FillTimesWith(int howmany, String what)
        {
            contents = "";
            for (int i = 0; i < howmany; i++)
            {
                contents = contents + what;
            }
        }
        public bool CharAtIs(int index, char c)
        {
            return contents[index]==c;
        }
        public void SetList(String[] strings)
        {
            contents = "";
            foreach (String s in strings)
            {
                contents = contents + s;
            }
        }
        //
        public char CharAt(int index)
        {
            return contents[index];
        }
    }
}

Python Source Code

# NOTES:
#   This Fixture is not sensible in Python.
#   Python does not worry about character arrays, strings are used instead.
#   Therefore, a TypeAdapter for char is not supported by PyFIT.
#   I supplied one in this package

from fitLib.DoFixture import DoFixture
from info.fitnesse.fixturegallery.typeadapter import buildListTypeAdapterFor

class DoFixtureTest(DoFixture):
    _typeDict = {
        "letters": "String"
    }

    def __init__(self):
        DoFixture.__init__(self)
        self.letters = ""

    # JAVA: void fillTimesWith(int count,char c){
    _typeDict["fillTimesWith.types"] = [None, "Integer", "Char" ]
    def fillTimesWith(self, count, c):
        self.letters = c * count    #< FILL: Repeat char ``count`` times.

    # JAVA: boolean charAtIs(int position, char c){
    _typeDict["charAtIs.types"] = ["Boolean", "Integer", "Char" ]
    def charAtIs(self, position, c):
        return self.letters[position] == c

    # JAVA: void setList(char[] array){
    ARRAY_OF_CHAR_TYPE_ADAPTER = buildListTypeAdapterFor("Char")
    _typeDict["setList.types"] = [ None, ARRAY_OF_CHAR_TYPE_ADAPTER ]
    def setList(self, array):
        self.letters = "".join(array)

    # JAVA: char charAt(int position){
    _typeDict["charAt.types"] = [ "Char", "Integer" ]
    def charAt(self, position):
        return self.letters[position]




Notes

DoFixture는 메소드 이름을 위해 prefix 될 수 있는 여러 키워드들을 제공합니다. 키워드가 사용되면 홀수번째 셀들이 메소드 이름으로 사용되게 됩니다. 짝수번째 셀들은 argument 값들이구요. 아래 일반적으로 사용되는 키워드들을 소개합니다.

  • reject will invert the logic of a test, returning TRUE will make the test fail if the row is prefixed with reject .
  • show will print out the value of a calculation in the test results (similar to an empty cell in ColumnFixture ).
  • check allows you to verify results of non-boolean calculations. Prefix the row with check and put the expected value of the calculation on the end of the row, in a new cell.



자바 버전에서는 check show 가 JavaBean 프로퍼티들과 곧바로 매핑 됩니다. 그러니까 get prifix를 사용하지 않으셔도 됩니다. 이런 키워드들은 public fields들로 사용될 수 없습니다. .NET 버전에서는 그것들을 field, 프로퍼티 그리고 메소드에 사용할 수 있습니다. 또한 .NET에서는 프로퍼티 값을 세팅하기 위해 set이라는 키워드를 사용하실 수도 있습니다.

!|DoFixtureTest|
|fill|10|times with|x|
|check|char at|4|x|
|set list|A,B,C,D|
|show|char at|2|



Usage

DoFixture는 workflow test나 어떤 특정한 반복 구조가 아닌 그런 테스트에 사용하실 수 있습니다. DoFixture는 다른 fixture들과 같이 coordinating 하는에 아주 유용합니다.

반응형