반응형
블로그 이미지
개발자로서 현장에서 일하면서 새로 접하는 기술들이나 알게된 정보 등을 정리하기 위한 블로그입니다. 운 좋게 미국에서 큰 회사들의 프로젝트에서 컬설턴트로 일하고 있어서 새로운 기술들을 접할 기회가 많이 있습니다. 미국의 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 하는에 아주 유용합니다.

반응형

CalculateFixture Tutorials - FitLibrary -

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


반응형

CalculateFixture



CalculateFixture는 여러 input arguments에 대한 한개 이상의 계산 결과를 verify 할 때 사용합니다. ColumnFixture와 같은 일을 합니다. 테이블 포맷은 다르지만요. 이 CalculateFixture는 ColumnFixture 보다 코딩량을 줄여주는 효과가 있습니다.






Table Format

첫번째 줄은 fixture class 이름 입니다. 그 다음 두번째 줄에는 input parameter들의 이름을 넣습니다. 그 다음엔 빈 cell 이 오고 그 빈 셀 다음에 calculation 이름 (output value)이 옵니다. 이후 모든 줄들은 input parameter와 예상되는 outcomes들이 옵니다. 빈 셀은 이 줄들에서도 input과 output을 구분해 주는 역할을 합니다.

!|CalculateFixtureTest|
|firstPart|secondPart||together|
|Hello|World||Hello, World|
|Houston|We Have a Problem||Houston, We Have a Problem|




Fixture Class

이 Fixture는 fitlibrary.CalculateFixture를 extend 합니다. 각 calculation 컬럼에 대해 하나이 메소드를 정의합니다. 이 메소드 이름은 모든 파라미터 이름들로 연결된 calculation 이름과 같아야 합니다. (아래 경우에는 togetherFirstPartSecondPart이 됨) 별도의 단어를 구분하기 위해 CamelCase nameing을 사용하실 수 있습니다.

Java Source Code

package info.fitnesse.fixturegallery;

import fitlibrary.CalculateFixture;

public class CalculateFixtureTest extends CalculateFixture{
	public String togetherFirstPartSecondPart(String firstPart,String secondPart){
		return firstPart+ ", "+secondPart;
	}
}

.NET Source Code

using fitlibrary;
using System;

namespace info.fitnesse.fixturegallery
{
	public class CalculateFixtureTest: CalculateFixture
	{
		public String TogetherFirstPartSecondPart(String firstPart,String secondPart)
		{
			return firstPart+ ", "+secondPart;
		}
	}
}

Python Source Code

from fitLib.CalculateFixture import CalculateFixture

class CalculateFixtureTest(CalculateFixture):
    _typeDict = {}

    # JAVA: String togetherFirstPartSecondPart(String firstPart,String secondPart){
    _typeDict["togetherFirstPartSecondPart.types"] = ["String", "String", "String"]
    def togetherFirstPartSecondPart(self, firstPart, secondPart):
        return "%s, %s" % (firstPart, secondPart)




Notes

이 메소드 이름들은 길어질 수 있습니다. 타이핑을 하다보면 에러를 발생시킬수 있습니다. 테이블을 작성하고 test를 실행시키세요. 처음에는 fail 할 겁니다.

Usage 같은 메소드나 같은 메소드 set들을 여러 input들을 가지고 실행하고 그 결과값을 확인하고  싶을 때 이 CalculateFixture를 사용합니다. 단지 메소드 실행만 필요하고 그 결과값은 별로 중요하지 않다면 혹은 method가 return 값이 없는 void 라면 SetUpFixture를 사용하시는게 더 좋을 겁니다. 프로퍼티들을 초기화 한 다음에 domain object에 대해 메소드를 실행하기 원한다면 ColumnFixture 가 더 유용할 겁니다. ColumnFIxture는 또한 calculation의 result를 테이블에서 확인하도록 하는 기능도 제공합니다. CalculateFixture는 빈 셀을 blank string으로 취급합니다. 그리고 이것을 result와 비교합니다. 그러니까 output cell 을 empty로 놓게 되면 columnFixture는 그 결과 값을 빈 셀에 출력하지만 CalculateFixture는 fail을 출력하게 될 겁니다.

반응형

SetUpFixture tutorial -FitLibrary-

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


반응형

FitLibrary

FitLibrary는 fixture의 third-party set으로 시작했습니다. 하지만 이 기능이 하도 유용해서 지금은 standard test 타입의 하나로 간주되고 있습니다. 자바버전에서는 아직 별도의 라이브러리로 관리됩니다.






SetUpFixture


SetUpFixture는 아무것도 테스트하지 않고 싶을 때 ColumnFixture를 완벽하게 대신할 수 있는 fixture 입니다. 다른 fixture들을 위한 stage를 준비하기 위해서 사용하는 것이죠. 예를 들어 데이터메이스의 테이블에 row들을 insert하거나 이후의 테스트들에서 사용될 domain object들을 생성할 때 이 SetUpFixture를 사용하실 수 있습니다.




Table Format

첫번째 줄은 fixture 클래스 이름이 됩니다. 두번째줄은 객체의 프로퍼티 이름들 입니다. 이후의 모든 줄들은 프로퍼티값들을 가지게 됩니다. 이 SetUpFixture table 에는 output cell 이 없습니다. 모두 input에만 사용이 됩니다.

!|SetUpFixtureTest|
|player|post code|balance|
|John Smith|SW4 66Z|10.00|
|Michael Jordan|NE1 8AT|12.00|



Fixture class

이 fixture 클래스는 fitlibrary.SetUpFexture를 extend 하고 single method를 정의합니다. 메소드 이름은 연결된 테이블에 있는 프로퍼티 이름들과 같아야 합니다. (두개의 분리된 단어를 표현하려면 CamelCase capitalisation을 사용하시면 됩니다.) 이 메소드는 테이블의 각 컬럼들에 대해 하나씩의 argument를 가지게 됩니다.



Java Source Code

package info.fitnesse.fixturegallery;

import info.fitnesse.fixturegallery.domain.Player;

import java.util.ArrayList;
import java.util.List;

import fitlibrary.SetUpFixture;

public class SetUpFixtureTest extends SetUpFixture{
	public SetUpFixtureTest() {
		 Player.players.clear();
	}
	public void playerPostCodeBalance(String name, String postCode, double balance){
	 Player.addPlayer(name, postCode, balance) ;
 }
}

.NET Source Code

namespace info.fitnesse.fixturegallery
{
    public class SetUpFixtureTest : fitlibrary.SetUpFixture
    {
        public SetUpFixtureTest()
        {
            Player.players.Clear();
        }
        public void PlayerPostcodeBalance(string player, string postCode, decimal balance)
        {
            Player p = new Player();
            p.Name = player;
            p.PostCode = postCode;
            p.Balance = balance;
            Player.players.Add(p);
        }
       }
}

Python Source Code

from fitLib.SetUpFixture import SetUpFixture
from info.fitnesse.fixturegallery.domain.Player import Player

class SetUpFixtureTest(SetUpFixture):
    _typeDict = {}

    def __init__(self):
        Player.players = []

    # JAVA: void playerPostCodeBalance(String name, String postCode, double balance){
    _typeDict["playerPostCodeBalance.types"] = [ None, "String", "String", "Float" ]
    def playerPostCodeBalance(self, name, postCode, balance):
        Player.addPlayer(name, postCode, balance)




Notes

메소드 이름은 길어 질 수도 있습니다. 이런 긴 메소드 이름을 타이핑하다보면 에러가 발생할 수가 있습니다. 매뉴얼로 타이핑하는 대신 테이블을 작성하고 test를 run 하세요. 그러면 처음에는 fail 하게 될 겁니다.



Usage

SetUpFixture는 domain object들을 신속하게 initialise 하고자 할 때 사용하실 수 있습니다. 데이터베이스 테이블을 준비하거나 서로 다른 argument들을 pass 해서 메소드를 여러번 실행시키고자 할 때 사용하기 좋습니다.

result나 error verification이 중요할 때 이 SetUpFixture를 사용하지는 마세요. 그럴때는 ColumnFixture를 사용하시거나 CalculateFixture를 사용하시는게 더 좋습니다.

반응형