TestNG and YAML

1,732 views
Skip to first unread message

Cédric Beust ♔

unread,
Aug 12, 2010, 7:10:40 PM8/12/10
to testng...@googlegroups.com
Hi everyone,

I started experimenting with YAML as an addition to TestNG's XML format. The initial results are pretty promising and they result in files that are much smaller and more readable than testng.xml.

For example:

<!DOCTYPE suite SYSTEM "http://beust.com/testng/testng-1.0.dtd" >
 
<suite name="SingleSuite" verbose="2" parallel="false" thread-count="4"
    data-provider-thread-count="3">

  <parameter name="n" value="42" />

  <test name="Regression2">
    <groups>
      <run>
        <exclude name="broken" />
      </run>
    </groups>
    <parameter name="count" value="10"/>
    <classes>
      <class name="test.listeners.ResultEndMillisTest" />
    </classes>
  </test>
</suite>

becomes:

name: SingleSuite
verbose: 2
threadCount: 4
parameters: { n: 42 }
tests:
  - name: Regression2
    verbose: 2
    parameters: { count: 10 }
    excludedGroups: [ broken ]
    classes:
      - test.listeners.ResultEndMillisTest

The result is even more telling on bigger files:

-rw-r--r--  1 cbeust  502  17638 Aug  6 11:07 src/test/resources/testng.xml
-rw-r--r--  1 cbeust  502  10732 Aug 12 16:03 src/test/resources/testng.yaml

And if you want to see what this means for bigger files, here is testng.xml and testng.yaml.

If you want to try this on your own XML file, I wrote a converter. Start by downloading:


and then:

java -classpath testng-5.13.2beta.jar org.testng.internal.Yaml a.xml

This will output the .yaml file on the console.

You should be able to feed this yaml file directly back into TestNG (using the same jar file) and see the same test results (it's working with TestNG's 456 tests). The only missing feature that I know of right now is suite-files.

This is still experimental: I am working on a separate branch and I haven't decided whether I was going to make this a part of the distribution or not, but the idea of being able to use such a simple format to maintain suite files is very appealing. Oh and of course, the XML format is not going away, this would be purely an alternate way of specifying suite files.

Please let me know what you think.

--
Cédric


Felipe Knorr Kuhn

unread,
Aug 13, 2010, 10:25:25 AM8/13/10
to testng...@googlegroups.com
Hello Cédric,

It's been a while since I messed with YAML (Ruby frameworks), but it's very nice to see it again in TestNG :)

I converted one of my XML files and got a few questions (haven't tried running the tests and I don't remember all the syntax):

listeners- common.IntegracaoInterceptor
listeners- common.InvocationListener
listeners- org.uncommons.reportng.HTMLReporter

is this correct? Why not use an array instead?

- listeners
      - listener1
      - listener2

The same question goes to parameters:

parameters: { selenium.url: https://localhost/demo/ selenium.browser: *firefox /opt/firefox36/firefox-bin, selenium.firefoxProfile: /opt/firefox-profiles/firefox36-profile, selenium.port: 3737, selenium.host: localhost }

It's going to be quite a mess to work with parameters like this.

Will it be OK to have parameter values with spaces?

What happens if you have values with commas?

2010/8/12 Cédric Beust ♔ <ced...@beust.com>


--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to testng...@googlegroups.com.
To unsubscribe from this group, send email to testng-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.

Cédric Beust ♔

unread,
Aug 13, 2010, 12:42:40 PM8/13/10
to testng...@googlegroups.com
Hi Felipe,

On Fri, Aug 13, 2010 at 7:25 AM, Felipe Knorr Kuhn <fkn...@gmail.com> wrote:
Hello Cédric,

It's been a while since I messed with YAML (Ruby frameworks), but it's very nice to see it again in TestNG :)

I converted one of my XML files and got a few questions (haven't tried running the tests and I don't remember all the syntax):

listeners- common.IntegracaoInterceptor
listeners- common.InvocationListener
listeners- org.uncommons.reportng.HTMLReporter

is this correct? Why not use an array instead?

No, it's a bug, it should be:

listeners:
  - common.IntegracaoInterceptor
  - common.InvocationListener
  - org.uncommons.reportng.HTMLReporter

I fixed the generator (didn't upload it yet).



- listeners
      - listener1
      - listener2

The same question goes to parameters:

parameters: { selenium.url: https://localhost/demo/ selenium.browser: *firefox /opt/firefox36/firefox-bin, selenium.firefoxProfile: /opt/firefox-profiles/firefox36-profile, selenium.port: 3737, selenium.host: localhost }

You can define maps in two different ways:

parameters:
  n: 42
  p: 10

or

parameters: { n: 42, p: 10 }

The converter picks the latter, but once you have converted your file, you can reformat it to the first form is this particular map contains too many entries to be on a single line.

Similarly, lists can be either on a single line or multiple ones (note: [] for lists, {} for maps):

a: [ b, c, d ]

or

a:
  - b
  - c
  - d

 

It's going to be quite a mess to work with parameters like this.

Will it be OK to have parameter values with spaces?
What happens if you have values with commas?

In both cases, you just put double quotes around them:

parameters: { n: 42, p: 10, s: "a b c", t: "a,b" }

FYI, here is the full documentation:

http://code.google.com/p/snakeyaml/wiki/Documentation

--
Cédric


Reply all
Reply to author
Forward
0 new messages