vincentkok / gradle-gatling

Gradle project to demonstrate Gradle and Gatling integration
16 stars 3 forks source link

Improvement for source set #1

Open matlockx opened 11 years ago

matlockx commented 11 years ago

Maybe it's a better idea to use a dedicated source set for load-tests when u r using your stub for other projects, e.g. like this:

   def loadTestSourceDir = 'src/load-test/scala'
   def loadTestResourceDir = 'src/load-test/resources'

   repositories {
       mavenCentral()
       maven { url "http://repository.excilys.com/content/groups/public" }
   }

   configurations {
       loadTestCompile
       loadTestRuntime { extendsFrom loadTestCompile }
   }

   sourceSets {
       loadTest {
           scala.srcDir file(loadTestSourceDir)
           resources.srcDir file(loadTestResourceDir)
           compileClasspath = configurations.loadTestCompile
           runtimeClasspath = output + compileClasspath + configurations.loadTestRuntime
       }
   }

   dependencies {
       loadTestCompile("com.excilys.ebi.gatling.highcharts:gatling-charts-highcharts:1.4.3")
   }

   task gatling(dependsOn: 'compileLoadTestScala') << {
     logger.lifecycle(" ---- Executing all Gatling scenarios from: ${sourceSets.loadTest.output.classesDir} ----")
     sourceSets.loadTest.output.classesDir.eachFileRecurse { file ->
       if (file.isFile()) {
         //Remove the full path, .class and replace / with a .
         logger.debug("Tranformed file ${file} into")
         def gatlingScenarioClass = (file.getPath() - (sourceSets.loadTest.output.classesDir.getPath() + File.separator) - '    .class').replace(File.separator, '.')

         logger.debug("Tranformed file ${file} into scenario class ${gatlingScenarioClass}")
         javaexec {
             // I do not use this so
             main = 'com.excilys.ebi.gatling.app.Gatling'
             classpath = sourceSets.loadTest.output + sourceSets.loadTest.runtimeClasspath
             args  '-sbf',
                   sourceSets.loadTest.output.classesDir,
                   '-s',
                   gatlingScenarioClass,
                   '-rf',
                   'build/reports/gatling'
         }
       }
     }

     logger.lifecycle(" ---- Done executing all Gatling scenarios ----")
   }
kallekarlberg commented 11 years ago

Agree. I noticed that using test classes from .test. Also included my regular test classes. Un-good :-)

Also: since the Gatling dep pulls approx half the internet the dep-list in the IDE is a tad long.

Anyway. Thanks for the simple "plugin"