image

  • フォト Amazonギフト券
    ※この時計の時刻は、閲覧しているパソコンのものであり、必ずしも正確な時間とは限りません

検索

最近のトラックバック

無料ブログはココログ

« 2009-04-06 | トップページ | 2009-04-10 »

2009-04-08

2009-04-08

xmlunit の調査 (その2)

XMLUnit の XMLAssert は、うまく使えなかったので、
XMLUnit の Diff を使う事にした。

テスト用の2つの xml ファイルと、テストケースを示す。
$ cat hello1.xml
<struct>
  <int>  3  </int>
  <boolean>false</boolean>
</struct>

$ cat hello2.xml
<struct>
  <boolean>false</boolean>
  <int>3</int>
</struct>

$ cat SampleTest.rb
# $KCODE = 'utf8'

require 'pp'
require 'java'
require 'test/unit'
require 'xmlunit-1.2.jar'

import 'org.custommonkey.xmlunit.XMLUnit'
import 'org.custommonkey.xmlunit.Diff'
import 'org.custommonkey.xmlunit.DetailedDiff'

import 'org.xml.sax.InputSource'

class Utils
  def self.compare(file1, file2)
    source1 = InputSource.new(file1)
    source2 = InputSource.new(file2)
    Diff.new(source1, source2)
  end
end

class SampleTest < Test::Unit::TestCase

  def setup
    # pp "----- setUp"
  end

  def teardown
    # pp "----- tearDown"
  end

  def test_Diff
    myControlXML = "<struct><int>3</int><boolean>false</boolean></struct>";
    myTestXML = "<struct><boolean>false</boolean><int>3</int></struct>";
    myDiff = Diff.new(myControlXML, myTestXML);
    assert_equal(true, myDiff.similar(), "pieces of XML are similar " + myDiff.to_s)
    assert_equal(false, myDiff.identical(), "but are they identical? " + myDiff.to_s)
  end

  def test_DetailedDiff
    myControlXML = "<struct><int>3</int><boolean>false</boolean></struct>";
    myTestXML = "<struct><boolean>false</boolean><int>3</int></struct>";
    myDiff = DetailedDiff.new(Diff.new(myControlXML, myTestXML));

    #    myDiff.getAllDifferences.each do |d|
    #      pp d
    #    end
  end

  def test_Compare
    c = Utils::compare('hello1.xml', 'hello2.xml')
    assert_equal(false, c.similar())    # node の順番を無視して比較
    assert_equal(false, c.identical())
  end

  def test_Compare
    # 空白文字の差を無視する
    XMLUnit::setIgnoreWhitespace(true)

    c = Utils::compare('hello1.xml', 'hello2.xml')
    assert_equal(true, c.similar())     # node の順番を無視して比較
    assert_equal(false, c.identical())
  end
end

実行結果はこんなふうになる。
$ jruby SampleTest.rb
Loaded suite SampleTest
Started
...
Finished in 0.15 seconds.

3 tests, 4 assertions, 0 failures, 0 errors

xml を出力する jruby で書くツールの unit テストには、この方法を使ってみようと思う。
# ファイル経由で比較するなら、 java, ruby, jruby を問わずにテストできる。

ピックアップ:「200円台」弁当が続々登場, 文章から「筆者の気持ち」を推定して音声合成する, etc...

- http://trend.gyao.jp/internet/entry-36865.html
> ヤフー株式会社が株式会社GyaOを合弁化 動画配信サービス「GyaO」と「Yahoo!動画」統合へ|トレンド|無料動画 GyaO[ギャオ]|

- http://www.j-cast.com/2009/04/07038975.html
> J-CASTニュース : 「200円台」弁当が続々登場 生産追いつかない店も

- http://0-designing.com/2009/04/08/543.html
> iPhone で支出管理:デザインの秀逸な家計簿アプリ「Pennies」。 | ゼロ・デザイニング [0-designing]

- http://trendy.nikkeibp.co.jp/article/special/20090403/1025190/
> 仏像ブームはなぜ起きた? 展覧会、鑑賞ツアーが好調なワケ - エンタ - 日経トレンディネット

- http://blog.saishu.jp/archives/51490600.html
> Groovin' High:アメリカ、時価会計基準を緩和のなんだかなぁ - livedoor Blog(ブログ)

- http://www.moongift.jp/2009/04/boks/
> MOONGIFT: » Blueprint CSSのレイアウト設計をグラフィカルに行う「Boks」:オープンソースを毎日紹介

- http://slashdot.jp/it/article.pl?sid=09/04/07/009248
> NECが文章から「筆者の気持ち」を推定して音声合成する技術を開発 - スラッシュドット・ジャパン

« 2009-04-06 | トップページ | 2009-04-10 »

mokuji

2013年12月
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        

google

  • twitter
  • __
  • _
    Googleボットチェッカー

合わせて読む

  • 合わせて読む
    フィードメーター - katoy: cocolog あわせて読みたい

リンク