maiflai / gradle-scalatest

A plugin to enable the use of scalatest in a gradle Scala project.
The Unlicense
73 stars 35 forks source link

No tests are run #24

Closed xanderdunn closed 9 years ago

xanderdunn commented 9 years ago

This is the first time I'm attempting to use gradle and scalatest. I have scalatest working with sbt, but I'm attempting to switch over to gradle.

My build.gradle:

repositories {
    mavenCentral()
}
apply plugin: 'scala'
dependencies {
    compile 'org.scala-lang:scala-library:2.11.7'
    testCompile 'org.scalatest:scalatest_2.11:2+'
    testRuntime 'org.pegdown:pegdown:1.1.0'
}

I have my test sources in src/test/scala, as shown in the gradle docs.

gradle --version:

------------------------------------------------------------
Gradle 2.6
------------------------------------------------------------

Build time:   2015-08-10 13:15:06 UTC
Build number: none
Revision:     233bbf8e47c82f72cb898b3e0a96b85d0aad166e

Groovy:       2.3.10
Ant:          Apache Ant(TM) version 1.9.3 compiled on December 23 2013
JVM:          1.8.0_60 (Oracle Corporation 25.60-b23)
OS:           Mac OS X 10.10.5 x86_64

When I run grade test, I get this:

Xanders-MacBook-Pro:reinforcementLearning admin$ gradle test
:compileJava UP-TO-DATE
:compileScala UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:compileTestJava UP-TO-DATE
:compileTestScala UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test UP-TO-DATE

BUILD SUCCESSFUL

Total time: 0.654 secs

It's successfully compiling the project, but it isn't running any of the tests. I suspect I've simply made an elementary mistake in my build.gradle.

maiflai commented 9 years ago

Using gradle 2.6 you can use the plugin syntax to apply this plugin (there should be a link in the readme) - at the moment it looks as though you have only applied the scala plugin which supports junit and testng?

xanderdunn commented 9 years ago

@maiflai Thanks for your help!

I'm sure I'm just being dense with my gradle setup, but I'm still not having luck. I think you're referring to the build scripts shown on the gradle plugins page.

With this, it again builds but runs no tests:

repositories {
    mavenCentral()
}
apply plugin: 'scala'
dependencies {
    compile 'org.scala-lang:scala-library:2.11.7'
    testCompile 'org.scalatest:scalatest_2.11:2+'
    testRuntime 'org.pegdown:pegdown:1.1.0'
}
buildscript {
  repositories {
    maven {
      url "https://plugins.gradle.org/m2/"
    }
  }
  dependencies {
    classpath "com.github.maiflai:gradle-scalatest:0.9"
  }
}

apply plugin: "com.github.maiflai.scalatest"

Do you have an example of a working build.gradle that's using scalatest?

xanderdunn commented 9 years ago

Ok, this ended up working fine for me:

repositories {
    mavenCentral()
}
apply plugin: 'scala'
dependencies {
    compile 'org.scala-lang:scala-library:2.11.7'
    testCompile 'org.scalatest:scalatest_2.11:2+'
    testRuntime 'org.pegdown:pegdown:1.1.0'
}
buildscript {
  repositories {
    maven {
      url "https://plugins.gradle.org/m2/"
    }
  }
  dependencies {
    classpath "com.github.maiflai:gradle-scalatest:0.9"
  }
}

apply plugin: "com.github.maiflai.scalatest"

The key was that after setting this to my build.gradle, I had to not merely run gradle test, but first I had to gradle clean.

maiflai commented 9 years ago

Ah, yes - gradle caches the results of tasks based on inputs and outputs - if you make changes to the build script it can require a clean to purge existing state.

You shouldn't have to run clean again - tests will re-run automatically if you modify them or the main source that they are based on. Otherwise you will see the task marked as up to date. Sorry for the confusion.

maiflai commented 9 years ago

Sorry - I've been travelling away from a keyboard for the past few days.

Just following up on the modifications to your build script - the plugin syntax I was referring to is the simplified variant at the bottom of the plugins page:

plugins {
  id "com.github.maiflai.scalatest" version "0.9"
}

should be sufficient for a simple project; this automates the manual configuration of repository, dependency and plugin application.

xanderdunn commented 9 years ago

@maiflai

Thanks, this ended up working for me. It just took me some time to figure out that I had to put this plugins{} at the top of my build.gradle, but after any buildscript{} blocks.