2011年1月26日水曜日

bloggerでSyntax Highliteを使う方法

http://www.kuribo.info/2008/06/blogger-syntax-highlighter.html

のエントリを参考にやってみた。
行番号でない・・・。
Firefoxだと折り返しもされない。

あとでもうちょっと調べてみる。

2011年1月25日火曜日

SeleniumRCで自動テスト!〜セットアップ編〜

おはようございます。
作業環境をMacBookAir(Mac OS X 10.6.6 Snow Leopard)に移行したので、こちらにもSeleniumRC環境をつくろうとやってみました。
特にWindowsXPでセットアップしたときと違いはありませんでした。

MacBookAirのPHPのバージョンなどの環境は以下のとおりです。

hoge@hoge-MacBookAir:~$ php -v
PHP 5.3.3 (cli) (built: Aug 22 2010 19:41:55)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies

hoge@hoge-MacBookAir:~$ java -version
java version "1.6.0_22"
Java(TM) SE Runtime Environment (build 1.6.0_22-b04-307-10M3261)
Java HotSpot(TM) 64-Bit Server VM (build 17.1-b03-307, mixed mode)

hoge@hoge-MacBookAir:~$ pear -V
PEAR Version: 1.9.1
PHP Version: 5.3.3
Zend Engine Version: 2.3.0
Running on: Darwin hoge-MacBookAir.local 10.6.0 Darwin Kernel Version 10.6.0: Wed Nov 10 18:13:17 PST 2010; root:xnu-1504.9.26~3/RELEASE_I386 i386

SeleniumRCをダウンロードしよう

SeleniumRCを動かすためにJavaのバージョンは1.5以上が必要です。
先ほど調べたとおり、1.6.0_22なので問題ナッシング。
SleniumRCのダウンロードはこちら→http://seleniumhq.org/download/



selenium-remote-control-1.0.3.zipをダウンロードして、お好きなディレクトリで解凍してください。
(ターミナルから実行しやすい場所がいいと思います)

自分は

/Users/hoge/SeleniumRC_remote_control

のようにSeleniumRC_remote_controlというディレクトリを作成し設置しました。


PHPUnitをインストールしよう

次、PHPUnitのインストールをします。(詳しくはこちら:http://www.phpunit.de/manual/3.5/ja/installation.html
PHPUnit3.5はPHP5.3.3以上を推奨しています。
PHPUnitはpearでインストールします。

pearのチャンネルサーバーの登録

# pear channel-discover pear.phpunit.de
Adding Channel "pear.phpunit.de" succeeded
Discovery of channel "pear.phpunit.de" succeeded

# pear channel-discover components.ez.no
Adding Channel "components.ez.no" succeeded
Discovery of channel "components.ez.no" succeeded

# pear channel-discover pear.symfony-project.com
Adding Channel "pear.symfony-project.com" succeeded
Discovery of channel "pear.symfony-project.com" succeeded

これでチャンネルサーバーからPHPUnitのパッケージをインストールすることが出来ます。
さっそくインストールをしましょう。
# pear install phpunit/PHPUnit

hoge@hoge-MacBookAir:~$ phpunit -v
PHPUnit 3.5.6 by Sebastian Bergmann.

こんな感じでとくに問題なくセットアップできました。
インストールするバージョンによってはpearの本体の依存関係や、他のパッケージが必要な場合があるので環境を整えてみてください。

・PEAR本体のアップグレード
# pear upgrade PEAR
・依存パッケージをまとめてインストール
# pear install -a phpunit/PHPUnit

さっそく動かしてみよう

SeleniumRCのサイトにサンプルコードがあるので(PHP版は無いw)、それを参考にGoogleアクセスして「hello world」で検索し、titleに「hello world ‐ Google 検索」と表示されるか確認するテストを書いてみました。

set_include_path(get_include_path() . PATH_SEPARATOR . './PEAR/');
require_once 'Testing/Selenium.php';
require_once 'PHPUnit/Framework/TestCase.php';

class GoogleTest extends PHPUnit_Framework_TestCase
{
    private $selenium;

    public function setUp()
    {   
        $this->selenium = new Testing_Selenium("*firefox3", "http://www.google.com");
        $this->selenium->start();
    }   

    public function testGoogle()
    {   
        $this->selenium->open("/");
        $this->selenium->type("q", "hello world");
        $this->selenium->click("btnG");
        $this->selenium->waitForPageToLoad(10000);
        $this->assertRegExp("/hello world - Google 検索/", $this->selenium->getTitle());
    }   

}


Seleniumサーバーを起動して
hoge@hoge-MacBookAir:~/SeleniumRC_remote_control$ java -jar selenium-server-1.0.3/selenium-server.jar

作ったテストコードを実行します。
hoge@hoge-MacBookAir:~/SeleniumRC_remote_control$ phpunit test_google.php
PHPUnit 3.5.6 by Sebastian Bergmann..

Time: 8 seconds, Memory: 4.75Mb

OK (1 test, 1 assertion)

Firefoxがかってに動いた!!
アサーションもOKだし、やったね!

2011年1月21日金曜日

あけおめショートエントリ今年の目標編




あけおめ、ことよろ。(遅)

多くの人が毎年ブログ続けるぞ!と目標立てて
3日坊主になってると思います(私もですw)

しかし、今年こそはと気持ちを切り替え12月に今年俺は頑張った!
自分にご褒美(笑)をやりたいので、頑張ってみようと思います。

自分の目標は、

「ひと月に2エントリ書く」

にしました。
長い文章が書くことが必ずしもいいとは思いませんが、
短いエントリは抜いて2エントリ書こうと思います。

頑張ります。