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

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

글 보관함

카테고리

RowFixture Tutorial (Fitnesse)

2013. 8. 14. 21:43 | Posted by 솔웅


반응형

RowFixture



RowFixture 는 객체들의 다이나믹한 리스트를 테스트합니다. Expected list (FitNesse Table)와 실제 결과 리스트 (fixture code로부터 도출된)를 비교하게 됩니다. 그리고 추가되고나 missing 된 아이템들을 report 하게 되는 거죠.

Table Format


테이블의 첫번째 줄은 fixture class 이름 입니다. 두번째 줄은 리스트 내의 객체들 구조를 나타내구요. (verify 하기를 원하는 프로퍼티들이나 메소드들이 되겠죠.). 그 이후에 나오는 줄들은 배열에 있는 expected objects 들입니다.

!include -seamless SetUpFixture

!|RowFixtureTest|
|name|post code|
|John Smith|SW4 66Z|
|Michael Jordan|NE1 8AT|


Fixture class


이 fixture class는 fit.RowFixture 를 extend 해야 하고 아래 두개의 메소드들을 오버라이드 해야 합니다.

  • getTargetClass — returns the Type or Class object representing the type of objects contained in the array.
  • query — returns the actual array of objects to be verified.
# section Java Source Code

Java Source Code

package info.fitnesse.fixturegallery;

import info.fitnesse.fixturegallery.domain.Player;
import fit.RowFixture;

public class RowFixtureTest extends RowFixture{
	public Class getTargetClass() {
		return Player.class;
	}
	public Object[] query() throws Exception {
			return Player.players.toArray();
	}
}

.NET Source Code

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

namespace info.fitnesse.fixturegallery
{
    public class RowFixtureTest: fit.RowFixture
    {
        public override Type GetTargetClass()
        {
            return typeof(Player);
        }
        public override object[] Query()
        {
            return Player.players.ToArray();
        }
    }
}

Python Source Code

from fit.RowFixture import RowFixture
from info.fitnesse.fixturegallery.domain.Player import Player

class RowFixtureTest(RowFixture):
    def getTargetClass(self):
        return Player

    def query(self):
        return list(Player.players) #< Return copy of players

Notes


그 객체가 identity (primary key 같은)의 한 부분이 되는 프로퍼티들을 가지고 있다면 그 프로퍼티들의 리스트들은 부가 정보 리스트들의 왼쪽에 놓여지게 됩니다. 이렇게 하면 error report를 보기가 훨씬 쉬워집니다. Figure 1을 봐 보세요. 두 클래스 모두 에러는 같습니다. 하지만 그 컬럼의 순서로 인해 하나는 주요 항목에 대한 에러를 알아보기가 쉽도록 보여주고 다른 하나는 모든 줄이 missing 되 버리게 됩니다.


Figure 1: RowFixture maps rows to objects from left to right



query method 다른 추가적인 argument들을 pass 하도록 허용하지 않습니다. 좀 더 자세한 정보를 보시려면 Fixture Arguments를 보세요.

리스트의 element들의 순서는 상호 의존적이지 않습니다. RowFixture 는 이를 무시할 겁니다.

Usage


객체들의 리스트를 verify 하려면 Use RowFixture 를 사용해서 테스트 하세요. 혹은 리스트 내의 모든 리스트들에 method를 만들어서 실행하셔도 됩니다. (이러면 번거롭겠죠?)


element 의 순서가 중요할 때는 이 RowFixture를 사용하지 마세요. 대신 ArrayFixture를 사용하세요.


반응형

ActionFixture Tutorial (Fitnesse)

2013. 8. 14. 10:23 | Posted by 솔웅


반응형

ActionFixture


ActionFixture 는 기본적으로 반복적인 경우가 아니라 workflow-style test를 위한 겁니다. 다른 fixture들을 automate 하기 위해 UI metaphor 를 사용합니다.



Table Format


ActionFixture table의 첫번째 줄(row)은 fixture class를 initialise합니다. 이 경우에는 다른 custom subclass가 아니라  ActionFixture 그 자체가 되겠습니다. 다른 모든 row들은 command cell 로 시작됩니다. 그리고 이 후의 cell 들에는 command argument들이 이어서 들어옵니다. 어떤 row들은 두개를 어떤 줄들은 3개의 셀들을 가집니다.

두번째 줄은 주로 start command 로 사용됩니다. 하나의 argument를 필요로 하죠. 그리고 automate 하는 실제 fixture의 클래스 이름이 옵니다. 그 다음에 테스트를 하기 위해 다른 command들을 사용하실 수 있습니다.

  • check — executes a method and verifies its value.
  • press — executes a void method without testing anything.
  • enter — executes a method and passes an argument to it.


여러분은 ActionFixture 를 UI form들을 populate 하고 method들과 연결된 버튼을 click 하기 위한 automation tool로 생각하셔도 됩니다.


!|ActionFixture|
|start|ActionFixtureTest|
|enter|firstPart|Hello|
|enter|secondPart|World|
|press|join|
|check|together|Hello, World|

(이 이미지는 source code와 다른 화면 입니다.)


Fixture class


다른 Fixture와 ActionFixture 가 다른 점은 따로 ActionFixture 를 extend 하지 않아도 된다는 겁니다. ActionFixture 대신에 fit.Fixture class를 곧바로 extend 합니다.



Java Source Code

package info.fitnesse.fixturegallery;

public class ActionFixtureTest extends fit.Fixture{
	private String first, second, both;
	public void firstPart(String s){
		first=s;
	}
	public void  secondPart(String s){
		second=s;
	}
	public void join(){
		both=first+ ", "+second;
	}
	public String together(){
		return both;
	}
}

.NET Source Code

using System;

namespace info.fitnesse.fixturegallery
{
	public class ActionFixtureTest: fit.Fixture
	 {
		public String firstPart, secondPart, together;
		public void join()
		{
			together=firstPart+ ", "+secondPart;
		}
	}
}

Python Source Code

from fit.Fixture import Fixture

class ActionFixtureTest(Fixture):
    _typeDict = {}

    def __init__(self):
        Fixture.__init__(self)
        self.__first  = ""    #< Private attributes (Python convention).
        self.__second = ""
        self.__both   = ""

    # JAVA: void firstPart(String s)
    _typeDict["firstPart"] = "String"
    def firstPart(self, s):
        self.__first = s

    # JAVA: void  secondPart(String s)
    _typeDict["secondPart"] = "String"
    def secondPart(self, s):
        self.__second = s

    # JAVA: void join()
    _typeDict["join"] = "Default"      #< AUTO-DETECT: None = void
    def join(self):
        self.__both = "%s, %s" % (self.__first, self.__second)

    # JAVA: String together()
    _typeDict["together"] = "String"
    def together(self):
        return self.__both


Notes

In the Java version, ActionFixture only works on methods. in the .NET version, enter and check can get and set fields and properties as well.
자바 버전에서는 ActionFixture 가 오직 method에 대해서만 적용됩니다. .NET 버전에서는 enter 와 check 이 필드와 프로퍼티들을 get,set 할 수 있습니다.



Usage


여러분은 ActionFixture 를 UI-style verification들을 처리하기 위해 사용하실 수 있습니다.

일반적으로 ActionFixtureDoFixture (see DoFixture )에 의해 replace 됩니다. 요즘은 이 ActionFixture를 써야 되는 경우가 한정돼 있죠. DoFixture 도 workflow-style 테스트를 할 수 있도록 기능을 제공 합니다. 사실 훨씬 더 쉽게 사용할 수 있도록 해 줍니다. DoFixture 가 fixture와 FitNesse table 모두 더 적은 코딩을 할 수 있도록 해 주고요.  DoFixture는 direct domain object wrapping 도 지원합니다.


반응형

ColumnFixture Tutorial (Fitnesse)

2013. 8. 12. 10:38 | Posted by 솔웅


반응형

Fitnesse에 대해서 공부하려고 하는데 검색을 해 봐도 별로 맘에 드는 블로그를 못 찾겠네요. 그래서 Fitnesse 홈페이지에 있는 Tutorial을 한번 쪽 훑어 보겠습니다.

기초적인 Research는 된 것 같아서 Fixture에 대한 부분을 살펴 봅니다.

여기로 가시면 Tutorial 원문을 보실 수 있습니다.

ColumnFixture


ColumnFixture 는 table 의 컬럼들을 곧바로 fixture class의 프로퍼티와 메소드 그리고 필드들로 매핑합니다. 이는 같은 테스트가 다양한 입력 argument들에 대해 반복적으로 사용되어야 할 때 반복적으로 사용되는 변수들을 만들 때 아주 유용합니다.

Table Format


테이블의 첫번째 줄(row)는 테스트 클래스의 이름입니다. 두번째 row의 컬럼 이름들은 이 컬럼과 관계된 필드나 메소드를 가리킵니다. Output 값들은 반드시 필드나 메소드 이름 다음에 ? 나 ()를 를 붙여야 합니다. 그 이후의 row들은 input argument들과 기대되는 결과값(output arguments)들의 combination list들 입니다.

!|info.fitnesse.fixturegallery.ColumnFixtureTest|
|firstPart|secondPart|together?|totalLength?|
|Hello|World|Hello, World|10|
|Houston|We Have a Problem|Houston, We Have a Problem|24|

Fixture class


fixture 클래스는 fit.ColumnFixture를 extend 해야 합니다. 그리고 테이블의 두번째 줄과 매치되는 public field들과 메소드들을 선언합니다.




Java Source Code

package info.fitnesse.fixturegallery;

import fit.ColumnFixture;

public class ColumnFixtureTest extends ColumnFixture {
	public String firstPart;
	public String secondPart;
	private int length;
	public String together(){
		length=firstPart.length()+secondPart.length();
		return firstPart+ ", "+secondPart;
	}
	public int totalLength(){
		return length;
	}
}

.NET Source Code

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

namespace info.fitnesse.fixturegallery
{
    public class ColumnFixtureTest: fit.ColumnFixture
    {
        public String firstPart;
        public String secondPart;
        public String Together
        {
            get
            {
                return firstPart + ", " + secondPart;
            }
        }
        public int TotalLength()
        {
            return firstPart.Length+secondPart.Length;
        }
    }
}

Python Source Code

from fit.ColumnFixture import ColumnFixture

class ColumnFixtureTest(ColumnFixture):
    _typeDict = {
        "firstPart":  "String",
        "secondPart": "String"
    }

    def __init__(self):
        ColumnFixture.__init__(self)
        self.firstPart  = ""
        self.secondPart = ""

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

    # JAVA: public int totalLength(){
    _typeDict["totalLength"] = "Integer"
    def totalLength(self):
        return len(self.firstPart) + len(self.secondPart)


Notes


자바버전에서는 클래스 필드들은 오직 input으로 사용되고 클래스 메소드들은 output으로 사용될 수 있습니다. JavaBean 프로퍼티들은 직접적으로 support 되지는 않습니다. (getter들이 output method들의 역할을 할 겁니다. 여러분은 getCreditLimit와 같은 전체 메소드 이름을 명시해야 합니다. .NET 버전에서는 필드들과 프로퍼티들이 input과 output들로 사용될 수 있습니다. 게다가 파라미터가 없는 메소드들도 output으로 사용될 수 있습니다. Java implementation은 대소문자 구분을 합니다. (case sensitive) .NET 버전은 프로퍼티 이름들에 대소문자 구분을 무시합니다.

table row들은 top-down 으로 실행됩니다. cell들도 왼쪽에서 오른쪽으로 실행되구요. 만약 row들이 실행되는 사이에 어떤 특별한 cleanup을 해야 한다면  reset() 메소드를 override하시면 됩니다.

.NET 버전은 ColumnFixture 로 domain object들을 감쌉니다. 이렇게 하면 fixture내의 도메인 object들의 프로퍼티들과 메소드들을 재선언 하지 않고 ColumnFixture 를 사용할 수 있도록 해 줍니다. Target objects로 가시면 좀 더 자세한 내용을 보실 수 있습니다.

output cell 을 empty로 놔두면 아무것도 테스트 하지 않고 현재의 값이 표시 됩니다.

Usage

 
ColumnFixture 는 calculation-based business rule들과 state machine들에 대해 테스트를 만들 떄 적합합니다. 같은 타입의 calculation이 다른 input 값들을 받아서 결과를 테스트하는 작업을 할 때 아주 유용합니다.

만약 테스트가 반복적이지 않다면 ColumnFixture 를 사용하는 것이 아주 좋은 방법이 아닐 수 있습니다. DoFixture (see DoFixture )를 한번 고려해 보세요. 만약 object들의 다이나믹한 리스트를 테스트하시려면 ArrayFixture (see ArrayFixture) 나 RowFixture 를 사용하세요. 이 Fixture들은 contents들도 verify 하거든요.


사람들은 가끔 이 ColumnFixture 를 잘 못 사용하기도 합니다. 특히 domain object나 데이터베이스에 record들을 insert 할 때 말이죠. 이를 위해서는 테이블의 마지막 칼럼에서 Create 를 call 함으로서 추가적인 메소드를 실행시킵니다. 이 메소드는 OK 같은 status code를 return 합니다. 이것은 creation에 대한 비지니스 룰을 체크하기를 원할 때 사용하면 좋습니다. 다른 테스트들의 stage를 준비하기를 원하신다면 SetUpFixture (see SetUpFixture )를 사용하면 좋습니다. 이 Fixture는 test page를 좀 더 가독성 있도록 해 줍니다. 또한 코드량도 줄일 수 있습니다.


반응형