mardi 10 avril 2018

Run java tests from jar on remote server

I have problem with tests run from remote server. Download jar from nexus, and run test ng suite file like that:

java -jar tests.jar suite.xml

Problem: i can't run test.jar like that.

Structure:

  1. Project A
  2. Project B depends on Project A

Project A: Project with all test methods. This is external project, that i can't change. I can only include this project in my as dependency (download from local nexus).

Project B: Project with tests, that use classes and methods from Project A. My dependencies:

dependencies {
  compile 'org.testng:testng:6.11'
  compile 'net.qa:tools:1.0' // Project A
}

When i work in idea tests works just fine, but i need to execute them from CLI.

To create jar, that can be run anywhere, and it will have all required dependencies i create task:

jar {
  manifest {
    attributes "Main-Class": "org.testng.TestNG"
  }
  // all dependencies
  from {
    configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
  }
  // test ng run configuration
  from('src/test/resources') {
    include 'suite.xml'
  }
}

So, now jar contains Project A (with all dependencies) and Project B src files (.class), but when i trying to run:

java -jar tests.jar suite.xml

Get an error:

Cannot find class in classpath: ibra.tests.soundGeneratorTest

That mean i dont have my own src files? When i unzip my jar i can see them.

Maybe this is hard way. I've been searching for solution for two days on stack, but can't find anything.

Aucun commentaire:

Enregistrer un commentaire