Comparing two XML strings/files in Groovy/Java

后端 未结 3 1173
执念已碎
执念已碎 2020-12-31 15:36

I\'m writing unit tests for checking some XML builder.

Now I\'m running into the problem of syntactical differences between the expected result and the actual result

3条回答
  •  囚心锁ツ
    2020-12-31 15:57

    The question and the accepted answer (as of today) correspond to a legacy version of XMLUnit.

    For those interested in knowing how to do it with XMLUnit v2 on Groovy:

    def "XMLs must be identical"() {
        setup:
        def control = ''
        def test = '''
            
              
            
        '''
    
        when:
        Diff d = DiffBuilder.compare(Input.fromString(control))
            .withTest(Input.fromString(test))
            .ignoreWhitespace()
            .ignoreComments()
            .normalizeWhitespace()
            .build()
    
        then:
        !d.hasDifferences()
    }
    

    Perhaps there is a "groovier" way of doing it but I think it's OK for illustration purposes :)

提交回复
热议问题