maiflai / gradle-scalatest Goto Github PK
View Code? Open in Web Editor NEWA plugin to enable the use of scalatest in a gradle Scala project.
License: The Unlicense
A plugin to enable the use of scalatest in a gradle Scala project.
License: The Unlicense
Is is possible to control the log level of the tests being run? In my tests I'm seeing a lot of output like the following:
00:18:47.820 [ScalaTest-1-running-StatsGeneratorTest] DEBUG o.a.h.m.impl.MetricsSystemImpl - UgiMetrics, User and group related metrics 00:18:48.425 [ScalaTest-1-running-StatsGeneratorTest] DEBUG o.a.h.s.a.util.KerberosName - Kerberos krb5 configuration not found, setting default realm to empty 00:18:48.428 [ScalaTest-1-running-StatsGeneratorTest] DEBUG org.apache.hadoop.security.Groups - Creating new Groups object 00:18:48.432 [ScalaTest-1-running-StatsGeneratorTest] DEBUG o.a.hadoop.util.NativeCodeLoader - Trying to load the custom-built native-hadoop library... 00:18:48.434 [ScalaTest-1-running-StatsGeneratorTest] DEBUG o.a.hadoop.util.NativeCodeLoader - Failed to load native-hadoop with error: java.lang.UnsatisfiedL
Would like to be able to quiet that output, but have no idea if these even has anything to do with the scalatest plugin vs the tests themselves.
Thanks,
Lance
I'm using version 0.22.
I'd like to show only failed tests in the output from gradle test
.
Here are things I have tried inside the test
task:
logging.level = LogLevel.ERROR
This resulted in no tests being shown at all. The test run failed due to failed tests though.
testLogging {
events "failed"
}
This showed all tests, also the successful ones.
testLogging {
info.events = ["failed"]
}
This showed all tests, also the successful ones.
logging.level = LogLevel.ERROR
testLogging {
error.events = ["failed"]
}
No tests were shown at all.
On windows I cant execute the testcompile statement https://stackoverflow.com/questions/50707110/gradle-windows-java-io-ioexception-createprocess-error-206-filename-is-too-lon as the path is too long.
A suggestion is to create a fat jar and execute the test cases only from the fat jar. Alternatively as the links suggest use the manifest trick. However, as far as I understand this needs to be applied directly to the plugin (grails, findbugs, sonarqube) all had similar problems.
I've setup my gradle build script according to the instructions found here -- https://plugins.gradle.org/plugin/com.github.maiflai.scalatest -- but when I try to get gradle to do anything, I get this stacktrace, below.
I'm using Gradle 1.4 (I cannot upgrade to the latest version, unfortunately), Groovy: 1.8.6, JVM: 1.7.0_65 on Linux 2.6.32-431.40.2.el6.x86_64 amd64.
FAILURE: Build failed with an exception.
* Where:
Build file '/home/me/my-project/build.gradle' line: 21
* What went wrong:
A problem occurred evaluating root project 'my-project'.
> org/gradle/api/reporting/DirectoryReport
* Try:
Run with --info or --debug option to get more log output.
* Exception is:
org.gradle.api.GradleScriptException: A problem occurred evaluating root project 'my-project'.
at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:54)
[snip]
Caused by: java.lang.NoClassDefFoundError: org/gradle/api/reporting/DirectoryReport
at com.github.maiflai.ScalaTestPlugin$_apply_closure1.doCall(ScalaTestPlugin.groovy:23)
at org.gradle.api.internal.ClosureBackedAction.execute(ClosureBackedAction.java:58)
at org.gradle.util.ConfigureUtil.configure(ConfigureUtil.java:133)
at org.gradle.util.ConfigureUtil.configure(ConfigureUtil.java:113)
at org.gradle.api.internal.AbstractTask.configure(AbstractTask.java:425)
at org.gradle.api.internal.AbstractTask.configure(AbstractTask.java:58)
at org.gradle.api.internal.ClosureBackedAction.execute(ClosureBackedAction.java:50)
at org.gradle.api.internal.Actions$FilteredAction.execute(Actions.java:203)
at org.gradle.api.internal.DefaultDomainObjectCollection.all(DefaultDomainObjectCollection.java:110)
at org.gradle.api.internal.DefaultDomainObjectCollection.all(DefaultDomainObjectCollection.java:115)
at org.gradle.api.internal.DefaultDomainObjectCollection.withType(DefaultDomainObjectCollection.java:126)
at org.gradle.api.DomainObjectCollection$withType.call(Unknown Source)
at com.github.maiflai.ScalaTestPlugin.apply(ScalaTestPlugin.groovy:21)
at com.github.maiflai.ScalaTestPlugin.apply(ScalaTestPlugin.groovy)
When I create a new project using gradle init --type scala-library
, removing the RunWith JUnitRunner for the test, running gradle test
results in no test output to the console, and the test report shows no tests having been run.
This is the build.gradle:
plugins {
id "com.github.maiflai.scalatest" version "0.6-5-g9065d91"
}
// Apply the scala plugin to add support for Scala
apply plugin: 'scala'
// In this section you declare where to find the dependencies of your project
repositories {
// Use 'jcenter' for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
}
// In this section you declare the dependencies for your production and test code
dependencies {
// We use Scala 2.11 in our library project
compile 'org.scala-lang:scala-library:2.11.2'
// We use Scalatest for testing our library
testCompile 'junit:junit:4.11'
testCompile 'org.scalatest:scalatest_2.11:2.2.2'
testRuntime 'org.scala-lang.modules:scala-xml_2.11:1.0.2'
testRuntime 'org.pegdown:pegdown:1.1.0'
}
I'm on Gradle 2.1, and JDK 8
Stu,
I am running into a very weird issue, illustrated a simple project create in github:
gradle-scalatest-demo
In a nutshell, the cause is from a dependency on 'org.apache.cxf:cxf-rt-frontend-jaxws:3.1.5', gradle test will throw the exception java.lang.IncompatibleClassChangeError: Implementing class
and gradle test
hangs indefinitely.
Any insights will be greatly appreciated. Our jdk is 1.8.121
-Chris
I have the main source in java and using scalatest for testing with gradle build and use jacoco for coverage. following the example from: [link to example in github!]
https://github.com/sebastianharko/gradle-sonar-java-jacoco-scalatest-junit/blob/master/build.gradle
however, whenever I use this plugin, it will run all test and report well. but jacocoTestReport is always SKIPPED. Any idea? Thanks
-Chris
I get this when running gradlew --stacktrace test
:
Caused by: java.lang.NoClassDefFoundError: org/gradle/api/logging/configuration/ConsoleOutput
at com.github.maiflai.ScalaTestAction.color(ScalaTestAction.groovy:102)
at com.github.maiflai.ScalaTestAction$color$3.callStatic(Unknown Source)
at com.github.maiflai.ScalaTestAction.reporting(ScalaTestAction.groovy:124)
at com.github.maiflai.ScalaTestAction$reporting$0.callStatic(Unknown Source)
at com.github.maiflai.ScalaTestAction.getArgs(ScalaTestAction.groovy:130)
at com.github.maiflai.ScalaTestAction.makeAction(ScalaTestAction.groovy:71)
at com.github.maiflai.ScalaTestAction$makeAction.callStatic(Unknown Source)
at com.github.maiflai.ScalaTestAction.execute(ScalaTestAction.groovy:30)
at com.github.maiflai.ScalaTestAction.execute(ScalaTestAction.groovy)
at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:585)
at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:568)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)
... 60 more
My gradle version is 2.13.
Any workaround? Does the plugin have a dependency on a specific Gradle version, and if so, which one?
In multi gradle project case, we need to have scalatest to continue to run for all subprojects even some tests fail and be able to fail the overall build at the end.
We have implemented the following gradle script to capture junit test against java and using junit runner for using scalatest to test java code using (@RunWith(classOf[JUnitRunner]). Everything works great except using scalatest to test scala code.
After debugging the issue, I discovered that test.afterSuite
were never be invoked in testing scala case, (works when testing java) . Do you know the cause and a way to make it work? Thanks
-Chris L
rootProject.ext.testFailureCount = 0
task checkForDeferredTestFailure() << {
if (rootProject.testFailureCount) {
throw new Exception("There were ${testFailureCount} test failures.")
}
}
gradle.startParameter.setTaskNames (gradle.startParameter.taskNames << ":checkForDeferredTestFailure")
gradle.taskGraph.whenReady { taskGraph ->
taskGraph.allTasks.each { Task t ->
if (t instanceof org.gradle.api.tasks.testing.Test) {
def test = (Test) t
test.ignoreFailures = true
test.afterSuite { td, tr ->
// ----------------------------------------------------
// -- it never comes in here when testing scala code, but file when testing java code
// ----------------------------------------------------
if (td.getParent() == null) {
rootProject.testFailureCount += tr.getFailedTestCount()
}
}
}
}
}
We are using gradle 4.5 and gradle-scalatest 0.19. After applying the plugin published pom doesn't have dependencies in it.
I am using ./gradlew clean publishToMavenLocal to generate pom locally
I am trying to use gradle-scalatest to produce test report. I don't know why, errors are displayed in report from time to time. When i get some initialization error like a bad connection to db, test failed but reports show only successes and no failure at all... any ideas?
Hi,
It seems that 0.17 was not pushed to plugins.gradle.org.
Thanks!
Previously working config:
$ ./gradlew -version
Picked up _JAVA_OPTIONS: -Duser.name=mrt
------------------------------------------------------------
Gradle 2.13
------------------------------------------------------------
Build time: 2016-04-25 04:10:10 UTC
Build number: none
Revision: 3b427b1481e46232107303c90be7b05079b05b1c
Groovy: 2.4.4
Ant: Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM: 1.8.0_92 (Oracle Corporation 25.92-b14)
OS: Linux 4.8.0-58-generic amd64
And in my build gradle:
classpath 'com.github.maiflai:gradle-scalatest:0.13'
...
testCompile "org.scalatest:scalatest_2.11:2.2.6"
After upgrading gradle this breaks:
$ ./gradlew -version
------------------------------------------------------------
Gradle 3.5.1
------------------------------------------------------------
Build time: 2017-06-16 14:36:27 UTC
Revision: d4c3bb4eac74bd0a3c70a0d213709e484193e251
Groovy: 2.4.10
Ant: Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM: 1.8.0_102 (Oracle Corporation 25.102-b14)
OS: Mac OS X 10.11.6 x86_64
In build:
Caused by: groovy.lang.MissingMethodException: No signature of method: org.gradle.StartParameter.isColorOutput() is applicable for argument types: () values: []
I noticed when I added your plugin to IntelliJ that I wasn't seeing tests (like in #67), however I also noticed that that even in the Gradle log the output was corrupted with ASCII control characters.
plugins {
id "com.github.maiflai.scalatest" version "0.23"
}
repositories {
mavenCentral()
}
dependencies {
compile 'org.scala-lang:scala-library:2.11.12'
testCompile 'org.scalatest:scalatest_2.11:3.0.1'
testRuntime 'org.pegdown:pegdown:1.4.2'
}
apply plugin: 'scala'
import org.scalatest._
class ATest extends WordSpec {
"Hello" in {
}
}
If I run ./gradlew test
I get
> Task :test
Discovery starting.
Discovery completed in 39 milliseconds.
Run starting. Expected test count is: 1
ATest:
- Hello (6 milliseconds)
Run completed in 79 milliseconds.
Total number of tests run: 1
Suites: completed 2, aborted 0
Tests: succeeded 1, failed 0, canceled 0, ignored 0, pending 0
All tests passed.
If I run ./gradlew test | less
(piping through less).
ESC[36mDiscovery starting.ESC[0m
ESC[36mDiscovery completed in 43 milliseconds.ESC[0m
ESC[36mRun starting. Expected test count is: 1ESC[0m
ESC[32mATest:ESC[0m
ESC[32m- Hello (6 milliseconds)ESC[0m
ESC[36mRun completed in 85 milliseconds.ESC[0m
ESC[36mTotal number of tests run: 1ESC[0m
ESC[36mSuites: completed 2, aborted 0ESC[0m
ESC[36mTests: succeeded 1, failed 0, canceled 0, ignored 0, pending 0ESC[0m
ESC[32mAll tests passed.ESC[0m
BUILD SUCCESSFUL in 2s
2 actionable tasks: 2 executed
Intellij Is about the same.
�[36mDiscovery starting.�[0m
�[36mDiscovery completed in 47 milliseconds.�[0m
�[36mRun starting. Expected test count is: 1�[0m
�[32mATest:�[0m
�[32m- Hello (6 milliseconds)�[0m
�[36mRun completed in 90 milliseconds.�[0m
�[36mTotal number of tests run: 1�[0m
�[36mSuites: completed 2, aborted 0�[0m
�[36mTests: succeeded 1, failed 0, canceled 0, ignored 0, pending 0�[0m
�[32mAll tests passed.�[0m
I've tried this:
build.gradle
plugins {
id "com.github.maiflai.scalatest" version "0.6-5-g9065d91"
}
apply plugin: 'scala'
task wrapper(type: Wrapper) {
gradleVersion = '2.2'
}
repositories {
mavenCentral()
}
dependencies {
compile 'org.scala-lang:scala-library:2.+'
testCompile 'org.scalatest:scalatest_2.11:2.+'
}
src/main/scala/Foo.scala
object Foo {
def getZero() = 0
}
src/test/scala/Test.scala
import org.scalatest._
class FooSpec extends FunSpec with Matchers {
describe("The Foo object") {
describe("has a getZero method which") {
it("returns 0") {
Foo.getZero should be (0)
}
}
}
}
But when I run $ gradle test
, a java.lang.NoClassDefFoundError: org/pegdown/PegDownProcessor
is thrown. What am I doing wrong? Here is a repo with the test project, see the README for more details.
I am using gradle 2.12 and it seems like some functionality is going away.
:compileTestScala
useAnt has been deprecated and is scheduled to be removed in Gradle 3.0. The Ant-Based Scala compiler is deprecated, please see https://docs.gradle.org/current/userguide/scala_plugin.html.
fork has been deprecated and is scheduled to be removed in Gradle 3.0. The fork option for the scala compiler is deprecated, please see https://docs.gradle.org/current/userguide/scala_plugin.html.
The MS Windows command line CreateProcess function has a limit of 32,767 characters. (The CMD.EXE command processor has a 8192 character command line length limit.) The scalatest plug-in can create a command line exceeding the 32K limit due to a lengthy value for the "-cp" argument when there are a large number of dependencies. (We had a classpath value length of 40,529 characters). This issue does not occur with Java tests as the Gradle test plug-in is handling the classpath differently.
Too long of a command line results in the error:
java.io.IOException: CreateProcess error=206, The filename or extension is too long
The Maven Surefrie (testing) plugin had to deal with this issue -- see discussion here -- as has other gradle plug-ins such as the gradle-vaadin-plugin, the FindBugs plugin, the application plugin, and others.
The surefire discussion has some good information on possible solutions. In my borwsing, it appears most Gradle plug-ins are solving this issue via a manifest only jar that has a 'Class-Path' entry with all the JARs to use.
The ScalaTest runner has the ability to run a specific test by name (-t option) and a specific suite (-s option)
see: http://doc.scalatest.org/2.1.1/index.html#org.scalatest.tools.Runner$
It is useful to be able to use these when working with a specific test (so as to not have to run all tests).
Would it be possible to expose these options via the gradle plugin with some convention properties?
Alternatively, could you expose a convention property that lets the caller specify all of the args to be sent to ScalaTest Runner?
Using that property would set all of the args.
i.e. in ScalaTestAction, something like:
if(userSpecifiedArgs) {
javaExecHandleBuilder.setArgs(userSpecifiedArgs)
}
else {
javaExecHandleBuilder.setArgs(getArgs(t))
}
-oDS -PS8 -R /Users/dbrewster/Development/paxata2/paxata/distributions/hadoop-core/build/classes/java/test -R /Users/dbrewster/Development/paxata2/paxata/distributions/hadoop-core/build/classes/scala/test -u /Users/dbrewster/Development/paxata2/paxata/distributions/hadoop-core/build/test-results/test -h /Users/dbrewster/Development/paxata2/paxata/distributions/hadoop-core/build/reports/tests/test
Successfully started process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/bin/java''
Exception in thread "ScalaTest-main" java.lang.IllegalArgumentException: Runpath must be either zero or two args: List(-p, /Users/dbrewster/Development/paxata2/paxata/distributions/hadoop-core/build/classes/java/test, -p, /Users/dbrewster/Development/paxata2/paxata/distributions/hadoop-core/build/classes/scala/test)
at org.scalatest.tools.Runner$.parseCompoundArgIntoList(Runner.scala:2111)
at org.scalatest.tools.Runner$.parseRunpathArgIntoList(Runner.scala:2085)
at org.scalatest.tools.Runner$.runOptionallyWithPassFailReporter(Runner.scala:929)
at org.scalatest.tools.Runner$.main(Runner.scala:860)
at org.scalatest.tools.Runner.main(Runner.scala)
The issue is how the plugin is passing the -R options. You shouldn't be giving multiple -R args but instead on -R arg with each path separated by a ':' (ignoring windows...)
ScalaTestAction:139
I tried using the gradle-scalatest plugin with Gradle 4.0 (recently released), and it seems to work except that no tests are ever executed. After a bit of digging, I discovered it is because in Gradle 4.0, Test.getTestClassesDir()
has been deprecated with a replacement called Test.getTestClassesDirs()
(note the plural form of Dirs).
It looks like Gradle 4.0 now produces separate class compilation directories (including test class directories) for each source set. Since there are separate source sets for Java and Scala code, there are now separate test class directories for each of them (build/classes/java/test
and build/classes/scala/test
). Unfortunately, getTestClassesDir
returns only the first test class directory, which always is the Java test dir. This means that ScalaTest is executed using the Java test class directory, and of course, doesn't find any ScalaTest suites.
Probably the best fix is to check for Gradle version 4.0 or higher, and if 4.0, then use Test.getTestClassesDirs
instead, and pass them all to the -R
ScalaTest flag (with proper platform path separators of course).
Unfortunately, Test.getTestClassesDirs
was introduced in Gradle 4.0, which is why you cannot just switch to using it exclusively, as that would break compatibility with earlier versions of Gradle.
I am running my unit tests from within intellij using the gradle-pane: Tasks->verification->test
Previously, when using JUnitRunner annotation, the intellij test-pane would show a list of tests and their status. Now, having removed the annotation and adjusted the build.gradle to use maiflai, the tests run (textual output shows in the test-pane console), but the only thing in the test-pane status area is the message 'Test events were not received'
Advice?
Top level build.gradle is empty.
settings.gradle:
pluginManagement {
repositories {
maven {
url uri('http://SANITIZED/repo/')
}
}
}
rootProject.name = 'watery'
include 'modules/tart'
Module level build.gradle:
plugins {
// Apply the scala plugin to add support for Scala
id 'scala'
id 'com.github.maiflai.scalatest' version '0.22'
}
dependencies {
// Use Scala 2.11 in our library project
compile 'org.scala-lang:scala-library:2.11.8'
// Use Scalatest for testing our library
testCompile 'junit:junit:4.12'
testCompile 'org.scalatest:scalatest_2.11:3.0.4'
// Need scala-xml at test runtime
testRuntime 'org.scala-lang.modules:scala-xml_2.11:1.0.6'
testRuntime 'org.pegdown:pegdown:1.4.2'
}
// In this section you declare where to find the dependencies of your project
repositories {
// Use jcenter for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
}
test {
dependsOn 'cleanTest'
//Your previous task details (if any)
}
Hi,
Is there any way to configure this plugin so that scalatest shows the full stacktrace for failed tests?
When running the test task using Gradle 3.0, it fails with the following exception:
groovy.lang.MissingMethodException: No signature of method: org.gradle.StartParameter.isColorOutput() is applicable for argument types: () values: []
at com.github.maiflai.ScalaTestAction.color(ScalaTestAction.groovy:101)
at com.github.maiflai.ScalaTestAction$color$3.callStatic(Unknown Source)
at com.github.maiflai.ScalaTestAction.reporting(ScalaTestAction.groovy:123)
at com.github.maiflai.ScalaTestAction$reporting$0.callStatic(Unknown Source)
at com.github.maiflai.ScalaTestAction.getArgs(ScalaTestAction.groovy:129)
at com.github.maiflai.ScalaTestAction.makeAction(ScalaTestAction.groovy:70)
at com.github.maiflai.ScalaTestAction$makeAction.callStatic(Unknown Source)
at com.github.maiflai.ScalaTestAction.execute(ScalaTestAction.groovy:29)
at com.github.maiflai.ScalaTestAction.execute(ScalaTestAction.groovy)
at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:623)
at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:606)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)
Rather than forcing users to declare
testRuntime 'org.pegdown:pegdown:1.6.0'
in their build file - this library should declare it as a runtime dependency so that users get it transitively. That would simplify a lot of headache for users.
When running gradle test with the plugin install, I get the following error. Gradle version 1.9.
An exception or error caused a run to abort. This may have been caused by a problematic custom reporter.
java.io.FileNotFoundException: /home/username/src/xxx/build/reports/tests (No such file or directory)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.(FileOutputStream.java:212)
at java.io.FileOutputStream.(FileOutputStream.java:165)
at org.scalatest.tools.HtmlReporter.(HtmlReporter.scala:57)
at org.scalatest.tools.ReporterFactory.createHtmlReporter(ReporterFactory.scala:118)
at org.scalatest.tools.ReporterFactory.org$scalatest$tools$ReporterFactory$$getReporterFromConfiguration$1(ReporterFactory.scala:155)
at org.scalatest.tools.ReporterFactory$$anonfun$1.apply(ReporterFactory.scala:162)
at org.scalatest.tools.ReporterFactory$$anonfun$1.apply(ReporterFactory.scala:161)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
at scala.collection.Iterator$class.foreach(Iterator.scala:727)
at scala.collection.AbstractIterator.foreach(Iterator.scala:1156)
at scala.collection.IterableLike$class.foreach(IterableLike.scala:72)
at org.scalatest.tools.ReporterConfigurations.foreach(ReporterConfiguration.scala:37)
at scala.collection.TraversableLike$class.map(TraversableLike.scala:244)
at org.scalatest.tools.ReporterConfigurations.map(ReporterConfiguration.scala:37)
at org.scalatest.tools.ReporterFactory.getDispatchReporter(ReporterFactory.scala:161)
at org.scalatest.tools.Runner$.withClassLoaderAndDispatchReporter(Runner.scala:1643)
at org.scalatest.tools.Runner$.runOptionallyWithPassFailReporter(Runner.scala:703)
at org.scalatest.tools.Runner$.main(Runner.scala:573)
at org.scalatest.tools.Runner.main(Runner.scala)
scalatest is launched with the -P
argument.
The plugin should respect the configuration entered on the test
task.
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.
`buildscript { //For the plugins
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
maven {
url "http://nexus.nephila.com/nexus/content/groups/public"
}
}
dependencies {
classpath 'com.github.rholder:gradle-one-jar:1.0.4'
classpath 'com.bmuschko:gradle-nexus-plugin:2.3.1'
classpath "gradle.plugin.com.github.maiflai:gradle-scalatest:0.14"
}
}
apply plugin: 'com.github.maiflai.scalatest'`
`C:\Git_Workspace\Weather\weather.marketdata>gradlew -version
Build time: 2016-09-19 10:53:53 UTC
Revision: 13f38ba699afd86d7cdc4ed8fd7dd3960c0b1f97
Groovy: 2.4.7
Ant: Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM: 1.8.0_45 (Oracle Corporation 25.45-b02)
OS: Windows 7 6.1 amd64`
Hello, and thank you for your work on this plugin.
I tried both 0.16 and 0.17 versions (Gradle 4.1) :
// ...
ext.scala_major = '2.11'
dependencies {
classpath 'com.github.maiflai:gradle-scalatest:0.17'
}
// ...
apply plugin: 'com.github.maiflai.scalatest'
// ...
testCompile "org.scalatest:scalatest_$scala_major:3.0.1"
testRuntime 'org.pegdown:pegdown:1.4.2'
// ...
And a single simple test :
class RichDateSpec extends FlatSpec with Matchers {
private val fmt = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss")
private val TWO_AM = LocalTime.of(2, 0)
private val oneHourBefore = LocalDateTime.parse("2005-01-04T01:00")
private val oneHourAfter = LocalDateTime.parse("2005-01-04T03:00")
private val oneHourOneSecondBefore = LocalDateTime.parse("2005-01-04T00:59:59")
"timeTo invoked on a past time" should " map to tomorrow" in {
oneHourAfter.timeTo(TWO_AM) should be(23 hours)
}
"timeTo invoked on a future time" should " map to today" in {
oneHourBefore.timeTo(TWO_AM) should be(1 hour)
}
"timeTo " should "take seconds into account" in {
oneHourOneSecondBefore.timeTo(TWO_AM) should be((60 minutes) + (1 second))
}
}
All tests run perfectly fine in Idea.
But when invoking gradle test
I am facing this error :
java.lang.RuntimeException: Error creating extended parser class: null
at org.parboiled.Parboiled.createParser(Parboiled.java:58)
at org.pegdown.PegDownProcessor.<init>(PegDownProcessor.java:92)
at org.pegdown.PegDownProcessor.<init>(PegDownProcessor.java:71)
at org.pegdown.PegDownProcessor.<init>(PegDownProcessor.java:52)
at org.pegdown.PegDownProcessor.<init>(PegDownProcessor.java:45)
at org.scalatest.tools.HtmlReporter.<init>(HtmlReporter.scala:117)
at org.scalatest.tools.ReporterFactory.createHtmlReporter(ReporterFactory.scala:188)
at org.scalatest.tools.ReporterFactory.getReporterFromConfiguration(ReporterFactory.scala:239)
at org.scalatest.tools.ReporterFactory$$anonfun$createReportersFromConfigurations$1.apply(ReporterFactory.scala:248)
at org.scalatest.tools.ReporterFactory$$anonfun$createReportersFromConfigurations$1.apply(ReporterFactory.scala:247)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:234)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:234)
at scala.collection.Iterator$class.foreach(Iterator.scala:891)
at scala.collection.AbstractIterator.foreach(Iterator.scala:1334)
at scala.collection.IterableLike$class.foreach(IterableLike.scala:72)
at org.scalatest.tools.ReporterConfigurations.foreach(ReporterConfiguration.scala:42)
at scala.collection.TraversableLike$class.map(TraversableLike.scala:234)
at org.scalatest.tools.ReporterConfigurations.map(ReporterConfiguration.scala:42)
at org.scalatest.tools.ReporterFactory.createReportersFromConfigurations(ReporterFactory.scala:247)
at org.scalatest.tools.ReporterFactory.getDispatchReporter(ReporterFactory.scala:251)
at org.scalatest.tools.Runner$.withClassLoaderAndDispatchReporter(Runner.scala:1498)
at org.scalatest.tools.Runner$.runOptionallyWithPassFailReporter(Runner.scala:1010)
at org.scalatest.tools.Runner$.main(Runner.scala:827)
at org.scalatest.tools.Runner.main(Runner.scala)
Caused by: java.lang.IllegalStateException
at org.objectweb.asm.tree.ClassNode.<init>(ClassNode.java:197)
at org.parboiled.transform.ParserClassNode.<init>(ParserClassNode.java:41)
at org.parboiled.transform.ParserTransformer.extendParserClass(ParserTransformer.java:43)
at org.parboiled.transform.ParserTransformer.transformParser(ParserTransformer.java:38)
at org.parboiled.Parboiled.createParser(Parboiled.java:54)
... 23 more
Am I missing something ? Some configuration ? Not sure where I should look at unfortunately.
Thanks for your help.
I just thought it might be good to either (1) change the default, or (2) at least note this on the readme. Thoughts?
Example (with classnames etc. changed), with multiple threads:
$ ./gradlew cleanTest test
:cleanTest
: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
Discovery starting.
Discovery completed in 128 milliseconds.
Run starting. Expected test count is: 3
UtilTest:
MyObjectTest:
A MyObject
utilMethod1
- should initialize its MyObject-y things correctly (12 milliseconds)
- should do the first util stuff (25 milliseconds)
utilMethod2
- should do the second util stuff (2 milliseconds)
Run completed in 222 milliseconds.
Total number of tests run: 3
Suites: completed 3, aborted 0
Tests: succeeded 3, failed 0, canceled 0, ignored 0, pending 0
All tests passed.
BUILD SUCCESSFUL
Total time: 4.131 secs
However, when I set maxParallelForks
to 1 in build.gradle
:
$ ./gradlew cleanTest test
:cleanTest
: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
Discovery starting.
Discovery completed in 140 milliseconds.
Run starting. Expected test count is: 3
UtilTest:
utilMethod1
- should do the first util stuff (20 milliseconds)
utilMethod2
- should do the second util stuff (1 milliseconds)
MyObjectTest:
A MyObject
- should initialize its MyObject-y things correctly (2 milliseconds)
Run completed in 243 milliseconds.
Total number of tests run: 3
Suites: completed 3, aborted 0
Tests: succeeded 3, failed 0, canceled 0, ignored 0, pending 0
All tests passed.
BUILD SUCCESSFUL
Total time: 5.164 secs
If i run gradle test
twice in a row, without changing anything else in between, the tests are run twice.
I would expect this to use gradle up-to-date checks to prevent this from happening.
Hi,
i am trying to run some scala tests with this plugin with gradle and it compiles but I dont see any output of the tests being run on the console or on the file system.
So, I am not sure if the tests are being run ?
Could you please help out.
build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.github.maiflai:gradle-scalatest:0.5'
}
}
apply plugin: 'scalatest'
apply plugin: 'scala'
apply plugin: 'application'
Thanks
mohnish
Currently I don't see the way how to disable colored output for tests using plugin.
There are options for runner to disable colored output: http://www.scalatest.org/user_guide/using_the_runner
This would be very helpful because Jenkins output looks like this:
[32m- should build search parameters with a filter by archived (9 milliseconds)�[0m �[32m should build search parameters without a filter by archived�[0m �[32m - when archived is false (1 millisecond)�[0m �[32m- should build search parameters with a raw query (8 milliseconds)�[0m �[32m should build search parameters without a raw query�[0m �[32m - when query is null (1 millisecond)�[0m �[32m - when query is empty (1 millisecond)�[0m
Maybe there is some workaround I can use with currently available functionality?
I have attempted to filter scala tests a couple of ways without success:
task testSection1(type: Test) {
filter{
includeTestsMatching '*.BasicRddManipulationTest'
}
}
./gradlew :word-count:clean :word-count:testSection1
./gradlew :word-count:clean :word-count:test --tests BasicRddManipulationTest
./gradlew :word-count:clean :word-count:test --tests *.BasicRddManipulationTest
None of these combinations seem to do the trick resulting in no tests being run via version 0.11
. I went back to version 0.7
and tried the task filtering, it did run a single test, but unfortunately it seemed to be random which test it would actually run (not matching the name). Here is my build script:
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "com.github.maiflai:gradle-scalatest:0.11"
classpath "com.netflix.nebula:gradle-extra-configurations-plugin:3.0.3"
}
}
subprojects {
apply plugin: 'scala'
apply plugin: 'com.github.maiflai.scalatest'
apply plugin: "nebula.provided-base"
group 'com.bti360'
repositories {
mavenCentral()
}
ext {
sparkVersion = '1.4.1'
scalaVersion = '2.11'
}
dependencies {
provided "org.apache.spark:spark-core_${scalaVersion}:${sparkVersion}"
provided "org.scala-lang:scala-library:${scalaVersion}.+"
testCompile "com.holdenkarau:spark-testing-base_${scalaVersion}:${sparkVersion}_0.3.1"
testCompile "org.scalatest:scalatest_${scalaVersion}:2+"
}
test {
maxParallelForks = 1
}
tasks.withType(ScalaCompile) {
scalaCompileOptions.useAnt = false
}
//Create ubjerJar/fatJar/shadowJar excluding provided dependencies
jar {
from { (configurations.runtime - configurations.provided).collect { it.isDirectory() ? it : zipTree(it) } }
exclude('META-INF/INDEX.LIST', 'META-INF/*.SF', 'META-INF/*.DSA', 'META-INF/*.RSA')
}
}
sonar seems to have problem to read the output result from scalatest $buildDir/test-results
.
Basically, the sonar reports are missing for Unit Test Success
Failures
Tests Count
and Execution Time
. For either scalatest on testing java code or scala code.
While Scoverage has all the correct information.
p.s
The plugin I have for sonar are:
- Scalastyle
- Scoverage
The gradle plugins are:
- "org.sonarqube.gradle:gradle-sonarqube-plugin:1.1"
- 'org.github.ngbinh.scalastyle:gradle-scalastyle-plugin_2.11:0.7.2'
- 'org.scoverage:gradle-scoverage:1.0.9'
- 'com.github.maiflai:gradle-scalatest:0.10'
Am I missing some plugins and mis-configued any thing?
Thanks
-Chris L.
Add args.add('-o') in getArgs() method.
Since gradle 4.X the default lifecycle logging will only emit logging for a specific task if it exists at that level.
Successful test runs do not emit anything (At the lifecycle level)
An example is demonstrated in the latest release notes (For Gradle 4.1).
https://docs.gradle.org/current/release-notes.html
Basically, a perfect successful build will result in something like
./gradlew check
BUILD SUCCESSFUL in 42s
40 actionable tasks: 10 executed, 30 up-to-date
And no other print out.
By adding test.testLogging.events = [TestLogEvent.FAILED]
I was able to reduce the default output of scalatest to almost match what the java plugin does. However, it appears there is no way to hide the following output:
Discovery starting.
Discovery completed in 1 second, 744 milliseconds.
Run starting. Expected test count is: 1959
Run completed in 3 seconds, 631 milliseconds.
Total number of tests run: 1959
Suites: completed 35, aborted 0 Scopes: pending 130
Tests: succeeded 1959, failed 0, canceled 0, ignored 27, pending 0
All tests passed.
It would be nice if this behaviour was customizable.
The plugin is currently (version 0.13) unusable with Gradle 3. The colour output API was deprecated in late Gradle 2.x and removed in Gradle 3. The error I receive in Gradle 3 is:
No signature of method: org.gradle.StartParameter.isColorOutput() is applicable for argument types: () values: []
Dependending on your dependencies list, the plugin can cause a extremly large classpath to be created and thus breaking the windows limit. This will cause an error like
"A problem occurred starting process 'command 'C:\Program Files\Java\jdk1.8.0_111\bin\java.exe''
It be nice to have a better way of handling classpaths or a better error message
Example project with this issue. Within the dependecies.gradle if you remove all the dependencies below the line //remove all dependencies here. the test will pass
maiflai_test.zip
Here my entire build.gradle:
// scoverage = code coverage
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath 'org.scoverage:gradle-scoverage:1.0.9'
}
}
// scalatest = unit testing framework
plugins {
id "com.github.maiflai.scalatest" version "0.9"
}
apply plugin: 'scoverage'
repositories {
mavenCentral()
}
apply plugin: 'scala' // basic scala support
dependencies {
compile 'org.scala-lang:scala-library:2.11.7'
testCompile 'org.scalatest:scalatest_2.11:2+'
testRuntime 'org.pegdown:pegdown:1.1.0'
scoverage 'org.scoverage:scalac-scoverage-plugin_2.11:1.1.0', 'org.scoverage:scalac-scoverage-runtime_2.11:1.1.0'
}
apply plugin: "com.github.maiflai.scalatest"
test {
tags {
exclude 'org.scalatest.tags.CoverageAcceptanceTest'
exclude 'org.scalatest.tags.UnitTest'
}
}
testScoverage {
tags {
exclude 'org.scalatest.tags.NonCoverageAcceptanceTest'
}
}
When I run gradle clean && gradle test
or gradle clean && grade testScoverage
, I see output like this:
:test
Discovery starting.
Discovery completed in 89 milliseconds.
Run starting. Expected test count is: 1
Run completed in 147 milliseconds.
Total number of tests run: 0
Suites: completed 1, aborted 0
Tests: succeeded 0, failed 0, canceled 0, ignored 0, pending 0
No tests were executed.
BUILD SUCCESSFUL
In other words, it found 1 test to run, which is correct, but then it didn't actually run anything.
It's linked to my use of exclude tags. If I completely comment out the test{} and testScoverage{} blocks in my build.gradle, then running gradle test
will run all of my tests, as expected.
Why would it find tests and then not run any of them? The tests are actually failing, so if it did actually run them then the build would fail.
I have a gradle project. I am using scala 2.12.2
I have tried adding scalatest library
dependencies{ classpath "gradle.plugin.com.github.maiflai:gradle-scalatest:0.14" }
apply plugin: 'com.github.maiflai.scalatest'
dependencies { testCompile 'org.scalatest:scalatest_2.12:3.0.1' testRuntime 'org.pegdown:pegdown:1.4.2' }
Running gradle test
throws error
java.lang.IncompatibleClassChangeError: Implementing class at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:763) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at java.net.URLClassLoader.defineClass(URLClassLoader.java:467) at java.net.URLClassLoader.access$100(URLClassLoader.java:73) at java.net.URLClassLoader$1.run(URLClassLoader.java:368) at java.net.URLClassLoader$1.run(URLClassLoader.java:362) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:361) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:763) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at java.net.URLClassLoader.defineClass(URLClassLoader.java:467) at java.net.URLClassLoader.access$100(URLClassLoader.java:73) at java.net.URLClassLoader$1.run(URLClassLoader.java:368) at java.net.URLClassLoader$1.run(URLClassLoader.java:362) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:361) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at org.parboiled.transform.ParserTransformer.extendParserClass(ParserTransformer.java:43) at org.parboiled.transform.ParserTransformer.transformParser(ParserTransformer.java:38) at org.parboiled.Parboiled.createParser(Parboiled.java:54) at org.pegdown.PegDownProcessor.<init>(PegDownProcessor.java:92) at org.pegdown.PegDownProcessor.<init>(PegDownProcessor.java:71) at org.pegdown.PegDownProcessor.<init>(PegDownProcessor.java:52) at org.pegdown.PegDownProcessor.<init>(PegDownProcessor.java:45) at org.scalatest.tools.HtmlReporter.<init>(HtmlReporter.scala:117) at org.scalatest.tools.ReporterFactory.createHtmlReporter(ReporterFactory.scala:192) at org.scalatest.tools.ReporterFactory.getReporterFromConfiguration(ReporterFactory.scala:239) at org.scalatest.tools.ReporterFactory.$anonfun$createReportersFromConfigurations$1(ReporterFactory.scala:248) at scala.collection.TraversableLike.$anonfun$map$1(TraversableLike.scala:234) at scala.collection.Iterator.foreach(Iterator.scala:929) at scala.collection.Iterator.foreach$(Iterator.scala:929) at scala.collection.AbstractIterator.foreach(Iterator.scala:1417) at scala.collection.IterableLike.foreach(IterableLike.scala:71) at scala.collection.IterableLike.foreach$(IterableLike.scala:70) at org.scalatest.tools.ReporterConfigurations.foreach(ReporterConfiguration.scala:42) at scala.collection.TraversableLike.map(TraversableLike.scala:234) at scala.collection.TraversableLike.map$(TraversableLike.scala:227) at org.scalatest.tools.ReporterConfigurations.map(ReporterConfiguration.scala:42) at org.scalatest.tools.ReporterFactory.createReportersFromConfigurations(ReporterFactory.scala:247) at org.scalatest.tools.ReporterFactory.getDispatchReporter(ReporterFactory.scala:251) at org.scalatest.tools.Runner$.withClassLoaderAndDispatchReporter(Runner.scala:1498) at org.scalatest.tools.Runner$.runOptionallyWithPassFailReporter(Runner.scala:1010) at org.scalatest.tools.Runner$.main(Runner.scala:827) at org.scalatest.tools.Runner.main(Runner.scala)
I have tried scalatest gradle plugin 1.6
Tried using pegdown version 1.6
And all other combinations I can think of. But I am not able to fix this.
Is there anyone who is using scala 2.12.2 and successfully running scalatest. I want to know what version worked.
I tried this plugin, it did run scalatest very well, but the Jacoco cannot generated code coverage report. Not sure if this plugin is not designed to work with Jacoco, if it did, could someone publish a sample configure for Gradle 1.9 ? Thanks.
For example:
test {
maxHeapSize = '512m'
}
appears to be ignored in the command line that is executed
I'm not a gradle expert, and so this was pretty painful for me to track down. I'm converting an existing gradle build and Java codebase to using scalatest for testing. Upon installing the grade-scalatest plugin my tests spewed massive amounts of exceptions about not being able to instrument classes that were already instrumented.
Running gradle in debug mode showed that the jacoco agent was getting added twice on the command line for the tests. After poking around a bunch I found JacocoTestAction.groovy
which appears to add the jacoco JVM args.
I currently have the following in my gradle build and it is now working:
test.getActions().removeIf { a -> ("" + a.action).contains("com.github.maiflai.JacocoTestAction") }
I tried to build the plugin from source to try and test a fix, but I can't figure out how to make gradle load the plugin from my local disk/repo. I think the following change to JacocoTestAction.groovy
should work in most cases:
// Added check that jvmArgs don't already contain the jacoco args
if (jacoco && jacoco.enabled && !task.jvmArgs.contains(jacoco.getAsJvmArg())) {
task.jvmArgs jacoco.getAsJvmArg()
}
@gslowikowski found that no tests were run when trying to run the sbt-scoverage-samples project.
The gradle-scalatest plugin needs to escape any spaces in the path to the test classes directory.
I am trying to pass a config map value using this plugin, but have not been able to make it work. Is this supported?
http://doc.scalatest.org/2.2.6/#org.scalatest.Suite@configMapSection
The original gradle Test task supported running a single test via a system property.
Can we support the new TestFilter in scalatest?
We want to experiment with some flag options to configure scalatest reporter (http://www.scalatest.org/user_guide/using_the_runner, "Configuring reporters").
How do we provide these options to gradle-scalatest?
By now this plugin redefines test
task which is OK for Scala tests only. But when module contains Java tests there are no easy way to run them. As a workaround I suggest to rename test
task to scalaTest
for example.
Hi,
I'm using version 2.0.M5b of scalatest and I'm getting the following error:
IllegalArgumentException: Use of I was deprecated in ScalaTest 1.0 and removed in 1.5.
Here are the latest supported config options:
http://www.scalatest.org/user_guide/using_scalatest_with_sbt
Let me know if you need any more info.
Cheers,
Kevin
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.