Martin Sojka Keprta
Martin Sojka Keprta

Reputation: 27

Gradle script ignores TestNG xml file

I have a Gradle configuration for a test task:

task ClientTest(type : Test,dependsOn:'CopyAllToOneFolder'){
  copy {
    from 'build\\classes\\java\\main'
    into 'build\\classes\\java\\test'
  }
  useTestNG() {
    systemProperty 'headless', '1'
    suites '/src/test/resources/run/ClienPageTest.xml'
  }
}

I have an XML for TestNG suite:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Client test" >
  <parameter name="browsername" value="chrome"/>
  <parameter name="headless" value="true"/>

  <listeners>
    <listener class-name="Listeners.ReporterListener"/>
    <listener class-name="Listeners.TestResultListener"/>
    <listener class-name="Listeners.TestSuiteListener"/>
  </listeners>

  <test name="RegistrationTest">
    <classes>
      <class name="org.client.RegistrationTest"></class>
    </classes>
  </test>
</suite>

When I am launching these test from Inlelijj IDEA as TestNG with XML test are executed correctly. But when I am launching tests from Gradle it simply ignores them.

What is wrong here?

Upvotes: 1

Views: 1042

Answers (2)

Martin Sojka Keprta
Martin Sojka Keprta

Reputation: 27

Ok.. this was just a type problem. I missed ClienPage instead of ClientPage... Anyway... Problem occured but was handled by following

  • Add task which clean project every time before tests are launched and add dependency on it.

Upvotes: 0

madhead
madhead

Reputation: 33441

First of all: what are that copys in your test task? Why do you need them? Can you remove them totally or at least move them to a separate task. Test tasks should only do tests!

I bet the problem is in your suites path in TestNG configuration:

suites '/src/test/resources/run/ClienPageTest.xml'

This is an absolute path to the /src/ folder in the root of the FS. What you might want instead is:

suites '${projectDir}/src/test/resources/run/ClienPageTest.xml'

Upvotes: 1

Related Questions