ScalaTest with Scalajs: No tests get executed - scala

My test suits execute fine with jvm, but if I enable scalajs plugin in sbt and run sbt test I get the following output:
[info] Tests:
[info] - should finishTest1
[info] - should finishTest2
...
[info] - should finishTest100
[info] Run completed in 4 seconds, 580 milliseconds.
[info] Total number of tests run: 0
[info] Suites: completed 0, aborted 0
[info] Tests: succeeded 0, failed 0, canceled 0, ignored 0, pending 0
[info] No tests were executed.
[success] Total time: 4 s, completed Oct 29, 2019 1:27:24 PM
So it seems that the test might get executed, but the their results get ignored? I am not really sure where should I start in order to fix such problem.
The test file looks like this:
import org.scalatest._
class Tests extends FlatSpec with Matchers {
it should "finishTest1" in {
assert(... == ...)
}
...
}
Furthemore, although sbt test returns the above output, running the tests trough intellij results in java.lang.NoClassDefFoundError: org/scalatest/tools/Runner!

Related

SBT ScalaTest not showing any error details

I am running test cases after change code in business logic. I run test case, but it failing by simply saying NullPoinerException. But it not showing any detais about the issue. It is that:
> it:testOnly com.company.project.Module.write.AlertModuleSpraySpec -F
[trace] Stack trace suppressed: run last project-Module-read/it:testOnly for the full output.
[error] Could not run test com.company.project.Module.write.AlertModuleSpraySpec: java.lang.NullPointerException
[info] Run completed in 1 second, 973 milliseconds.
[info] Total number of tests run: 0
[info] Suites: completed 0, aborted 0
[info] Tests: succeeded 0, failed 0, canceled 0, ignored 0, pending 0
[info] All tests passed.
[error] Error during tests:
[error] com.company.project.Module.write.AlertModuleSpraySpec
[error] (project-Module-read/it:testOnly) sbt.TestsFailedException: Tests unsuccessful
[error] Total time: 2 s, completed 28 Nov, 2016 2:04:45 PM

Serenity BDD Timeout Error

I am running Serenity Jbehave Scripts with example table with 19 rows of values but the script is executing only 7 rows which are present in the example table and giving exception as below when executing the 8th row
The Stack trace from console is :
Example: {workspaceName=admin, menuName=Admin, menuOption=Parameter Maintenance, portletTitle=Parameter Maintenance}
Given login to CMS as colinw and colinw
Then I Navigate to admin Workspace
When I Select Parameter Maintenance Option from Admin Menu
Then I Verify Portlet Parameter Maintenance is Displayed
Then I Close the Portlet Parameter Maintenance
Then logout from CMS
Example: {workspaceName=admin, menuName=Admin, menuOption=Product Maintenance, portletTitle=Product Type}
Story stories/smoke/ShakeDownScript.story duration of 301 seconds has exceeded timeout of 300 seconds
(AfterStories)
[pool-2-thread-1] INFO net.thucydides.core.webdriver.SystemPropertiesConfiguration - project.build.directory : null
[pool-2-thread-1] INFO net.thucydides.core.webdriver.SystemPropertiesConfiguration - project.reporting.OutputDirectory : null
[pool-2-thread-1] INFO net.thucydides.core.webdriver.SystemPropertiesConfiguration - OutputDirectory : C:\WCG Automation\CMS\CMS_Automation\target\site\serenity
Given login to CMS as colinw and colinw
Then I Navigate to admin Workspace
Generating reports view to 'C:\WCG Automation\CMS\CMS_Automation\target\jbehave' using formats '[stats, console, html, xml, serenityreporter, junitscenarioreporter]' and view properties '{decorateNonHtml=true}'
Reports view generated with 0 stories (of which 0 pending) containing 0 scenarios (of which 0 pending)
Tests run: 47, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 313.246 sec <<< FAILURE! - in wcg.cms.CMSTestSuite
wcg.cms.CMSTestSuite Time elapsed: 3.651 sec <<< ERROR!
java.lang.RuntimeException:org.jbehave.core.embedder.Embedder$RunningStoriesFailed: Failures in running stories:
stories/smoke/ShakeDownScript.story: java.util.concurrent.CancellationException
at org.jbehave.core.embedder.Embedder$ThrowingRunningStoriesFailed.handleFailures(Embedder.java:553)
at org.jbehave.core.embedder.Embedder.handleFailures(Embedder.java:238)
at org.jbehave.core.embedder.Embedder.runStoriesAsPaths(Embedder.java:216)
at net.serenitybdd.jbehave.embedders.ExtendedEmbedder.runStoriesAsPaths(ExtendedEmbedder.java:60)
at net.serenitybdd.jbehave.runners.SerenityReportingRunner.run(SerenityReportingRunner.java:175)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:283)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:173)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:153)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:128)
Results :
Tests in error:
JUnit4Provider.invoke:128->executeTestSet:153->executeWithRerun:173->execute:283 ยป Runtime
Tests run: 47, Failures: 0, Errors: 1, Skipped: 0
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent! The file encoding for reports output files should be provided by the POM property ${project.reporting.outputEncoding}.
[INFO]
[INFO] --- serenity-maven-plugin:1.1.36:aggregate (serenity-reports) # CMS_Automation ---
[INFO] LOADING LOCAL PROPERTIES FROM C:\WCG Automation\CMS\CMS_Automation\serenity.properties
[INFO] LOADING LOCAL PROPERTIES FROM C:\WCG Automation\CMS\CMS_Automation\serenity.properties
[INFO] LOADING LOCAL PROPERTIES FROM C:\WCG Automation\CMS\CMS_Automation\serenity.properties
[INFO] webdriver.base.url=http://nssrvdfsdev01/calms2cms/
[INFO] serenity.project.name=Automation Testing
[INFO] webdriver.timeouts.implicitlywait=60000
[INFO] project.build.directory : C:\WCG Automation\CMS\CMS_Automation
[INFO] project.reporting.OutputDirectory : null
[INFO] OutputDirectory : C:\WCG Automation\CMS\CMS_Automation\target\site\serenity
[INFO] current_project.base.dir: C:\WCG Automation\CMS\CMS_Automation
Generating HTML Story Reports from C:\WCG Automation\CMS\CMS_Automation\target\site\serenity
Generating HTML Story Reports to C:\WCG Automation\CMS\CMS_Automation\target\site\serenity
[INFO] project.build.directory : C:\WCG Automation\CMS\CMS_Automation
[INFO] project.reporting.OutputDirectory : null
[INFO] OutputDirectory : C:\WCG Automation\CMS\CMS_Automation\target\site\serenity
Merging requirements = [Requirement{name='Smoke', type='feature' parent = 'null', cardNumber='null'}]
Merging requirements = []
Merged requirements set = [Requirement{name='Smoke', type='feature' parent = 'null', cardNumber='null'}]
[INFO] REPORTS GENERATED IN C:\WCG Automation\CMS\CMS_Automation\target\site\serenity
[INFO] REPORT HOME PAGE: C:\WCG Automation\CMS\CMS_Automation\target\site\serenity\index.html
[INFO] Generating release reports for: []
GENERATE CUSTOM REPORTS
[INFO]
[INFO] --- maven-failsafe-plugin:2.18.1:verify (default) # CMS_Automation ---
[INFO] Failsafe report directory: C:\WCG Automation\CMS\CMS_Automation\target\failsafe-reports
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent! The file encoding for reports output files should be provided by the POM property ${project.reporting.outputEncoding}.
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Skipping Sample Serenity project using JBehave and WebDriver
[INFO] This project has been banned from the build due to previous failures.
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 05:25 min
[INFO] Finished at: 2016-08-22T17:26:18+05:30
[INFO] Final Memory: 37M/416M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-failsafe-plugin:2.18.1:verify (default) on project CMS_Automation: There are test failures.
[ERROR]
[ERROR] Please refer to C:\WCG Automation\CMS\CMS_Automation\target\failsafe-reports for the individual test results.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
it appears that story execution is exceeding the timeout of 300 seconds . is there any way so that we can reset the 300 seconds to 600 seconds in the framework
The solution is quite simple.
I found a related question and answer here.
You can either run the tests with an extra argument like:
mvn clean verify -DstoryTimeoutInSecs=600
Or put a property in the serenity.properties file (which should be in the root of your project if you have it) like this:
story.timeout.in.secs=600

How can I fix evicted libraries and ambiguous reference error in Scala (Akka 2.4.0)?

I have code that uses the new Akka 2.4.0. Apparently I've got some libs that are compiled with earlier versions, so I get the warnings/errors shown.
Most problematic, I get an ambiguous reference problem shown below.
OK, so the compiler is warning me (I think) that it's bumped older Akka versions in favor of 2.4.0, then it's confused about akka.pattern.ask.
What should I do about it?
My output is below:
> test:compile
[info] Compiling 5 Scala sources to /Users/wmy965/git/hello/common/target/scala-2.11/test-classes...
[error] /Users/wmy965/git/hello/common/src/test/scala/common.test.service/FacilitiesTests.scala:16: ambiguous reference to overloaded definition,
[error] both method ask in trait AskSupport of type (actorSelection: akka.actor.ActorSelection, message: Any, sender: akka.actor.ActorRef)(implicit timeout: akka.util.Timeout)scala.concurrent.Future[Any]
[error] and method ask in trait AskSupport of type (actorSelection: akka.actor.ActorSelection, message: Any)(implicit timeout: akka.util.Timeout)scala.concurrent.Future[Any]
[error] match expected type ?
[error] import akka.pattern.ask._
[error] ^
[error] /Users/wmy965/git/hello/common/src/test/scala/common.test.service/FacilitiesTests.scala:43: value ? is not a member of akka.actor.ActorRef
[error] Error occurred in an application involving default arguments.
[error] val result = Misc.await(harness.facilities.mongoControl ? MongoAction({ mongo =>
[error] ^
[error] two errors found
[error] (common/test:compileIncremental) Compilation failed
[error] Total time: 1 s, completed Oct 23, 2015 5:57:17 PM
> evicted
[info] Updating {file:/Users/wmy965/git/hello/}hello...
[info] Updating {file:/Users/wmy965/git/hello/}common...
[info] Resolving jline#jline;2.12.1 ...
[info] Done updating.
[info] Resolving org.scala-lang.modules#scala-xml_2.11;1.0.4 ...
[warn] There may be incompatibilities among your library dependencies.
[warn] Here are some of the libraries that were evicted:
[warn] * com.typesafe.akka:akka-actor_2.11:(2.3.12, 2.3.7) -> 2.4.0 (caller: com.cof:common_2.11:reactive2_a6d8f9, com.typesafe.akka:akka-stream-experimental_2.11:1.0, co.blocke:laterabbit_2.11:0.3, com.typesafe.akka:akka-slf4j_2.11:2.4.0, com.thenewmotion.akka:akka-rabbitmq_2.11:1.2.4)
[info] Here are other libraries that were evicted:
[info] * org.slf4j:slf4j-api:(1.7.7, 1.6.0) -> 1.7.12 (caller: com.bionicspirit:shade_2.11:1.7.Z, org.mongodb:casbah-core_2.11:2.8.2, org.mongodb:casbah-gridfs_2.11:2.8.2, org.slf4j:slf4j-simple:1.7.7, com.typesafe.akka:akka-slf4j_2.11:2.4.0, org.mongodb:casbah-commons_2.11:2.8.2, org.mongodb:casbah-query_2.11:2.8.2)
[info] * org.mongodb:casbah_2.11:2.8.0 -> 2.8.2 (caller: com.cof:common_2.11:reactive2_a6d8f9, co.blocke:scalajack_mongo_2.11:4.4.1)
[info] * org.scala-lang:scala-reflect:2.11.0 -> 2.11.7 (caller: co.blocke:scalajack_2.11:4.4.1, org.monifu:monifu-core_2.11:0.7.0)
[info] * org.joda:joda-convert:1.2 -> 1.7 (caller: com.github.nscala-time:nscala-time_2.11:1.0.0, co.blocke:scalajack_2.11:4.4.1)
[info] * org.scala-lang:scala-library:(2.11.0, 2.11.5, 2.11.4) -> 2.11.7 (caller: com.bionicspirit:shade_2.11:1.7.Z, com.github.nscala-time:nscala-time_2.11:1.0.0, com.typesafe.akka:akka-http-experimental_2.11:1.0, com.typesafe.akka:akka-stream-experimental_2.11:1.0, co.blocke:laterabbit_2.11:0.3, org.mongodb:casbah-gridfs_2.11:2.8.2, co.blocke:scalajack_2.11:4.4.1, com.typesafe.akka:akka-slf4j_2.11:2.4.0, org.monifu:monifu-core_2.11:0.7.0, org.mongodb:casbah-core_2.11:2.8.2, com.cof:common_2.11:reactive2_a6d8f9, com.typesafe.akka:akka-http-core-experimental_2.11:1.0, com.typesafe.akka:akka-actor_2.11:2.4.0, org.scala-lang:scala-reflect:2.11.7 (), org.mongodb:casbah_2.11:2.8.2, com.typesafe.akka:akka-parsing-experimental_2.11:1.0, org.mongodb:casbah-commons_2.11:2.8.2, org.mongodb:casbah-query_2.11:2.8.2, co.blocke:scalajack_mongo_2.11:4.4.1, com.thenewmotion.akka:akka-rabbitmq_2.11:1.2.4)
[info] Resolving jline#jline;2.12.1 ...
[info] Done updating.
[success] Total time: 1 s, completed Oct 23, 2015 5:57:30 PM
To avoid ambiguity, you can either add sender() or ActorRef.noSender - depends on the context. Or add a timeout mongoControl.ask(MongoAction({...}))(1.second)

Execute multiple Scalatests in sbt

I have multiple IntelliJ (Scala) modules that have build.sbt file and scalatest code.
I also created ScalaTest configurations for each of them.
I can run the test one by one from the execution of sbt test.
Is it possible to execute all the tests at once? I can think of making a Python/Bash script, but I wonder if there is a simple way to do it.
for d in dirs:
execute("sbt test")
ADDED
From Alexey Romanov's answer, I created a build.sbt in the root directory with the following content
lazy val root = (project in file(".")).aggregate(context, contextProcessor)
lazy val context = project
lazy val contextProcessor = project
Then, I executed set test to make all the tests run.
[info] ContextTest:
[info] - Create context
[info] - Create context 2
[info] Run completed in 195 milliseconds.
[info] Total number of tests run: 2
[info] Suites: completed 1, aborted 0
[info] Tests: succeeded 2, failed 0, canceled 0, ignored 0, pending 0
[info] All tests passed.
[info] Compiling 1 Scala source to /Users/smcho/Desktop/code/ContextSharingSimulation/contextProcessor/target/scala-2.11/test-classes...
[info] DatabaseTest:
[info] - Create test
[info] - Create test2
[info] Run completed in 147 milliseconds.
[info] Total number of tests run: 2
[info] Suites: completed 1, aborted 0
[info] Tests: succeeded 2, failed 0, canceled 0, ignored 0, pending 0
[info] All tests passed.
[success] Total time: 5 s, completed Aug 12, 2015 3:03:41 PM
Reference - http://www.scala-sbt.org/0.13.5/docs/Getting-Started/Multi-Project.html
; <module1>/test; <module2>/test; <module3>/test
Or create an aggregate project:
// in build.sbt
lazy val root = (project in file(".")).
aggregate(<module1>, ...)
Now you can just run sbt test. Actually, it should already be there by default:
If a project is not defined for the root directory in the build, sbt creates a default one that aggregates all other projects in the build.

Execution order of ScalaTest and JUnit tests using IntelliJ and Maven

My team is using Scala, IntelliJ, and Maven.
In the some of the tests I need for the current module I am working on the internal test order of execution is important.
For some reason running the same test using JUnit or ScalaTest in IntelliJ effects the order of execution.
For example, the following test:
package com.liveperson.lpbt.hadoop.monitoring.temp
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
import org.scalatest.{FunSuite, BeforeAndAfterAll}
#RunWith(classOf[JUnitRunner])
class TempTest extends FunSuite with BeforeAndAfterAll{
println("start TempTest")
override def beforeAll(){
println("beforeAll")
}
override def afterAll(){
println("afterAll")
}
test("test code"){
println("in test code")
}
println("end TempTest")
}
When running with JUnit the above code prints outs:
start TempTest
end TempTest
in test code
beforeAll
afterAll
When running with ScalaTest the above code prints outs:
start TempTest
end TempTest
beforeAll
in test code
afterAll
Does somebody knows how to write such test ensuring the order of execution in both ScalaTests and JUint?
Also, how do you switch between them in IntelliJ?
Can you elaborate on exactly how you got the JUnit output? I just tried doing your class from the command line and got the expected output (different from yours):
Mi-Novia:roofSoccer bv$ scala -cp ~/.m2/repository/junit/junit/4.8.1/junit-4.8.1.jar:target/jar_contents/ org.scalatest.run TempTest
start TempTest
end TempTest
Discovery starting.
Discovery completed in 19 milliseconds.
Run starting. Expected test count is: 1
beforeAll
TempTest:
in test code
- test code
afterAll
Run completed in 140 milliseconds.
Total number of tests run: 1
Suites: completed 1, aborted 0
Tests: succeeded 1, failed 0, canceled 0, ignored 0, pending 0
All tests passed.
Mi-Novia:roofSoccer bv$ scala -cp ~/.m2/repository/junit/junit/4.8.1/junit-4.8.1.jar:target/jar_contents/ org.junit.runner.JUnitCore TempTest
JUnit version 4.8.1
Could not find class: TempTest
Time: 0.001
OK (0 tests)
Mi-Novia:roofSoccer bv$ scala -cp ~/.m2/repository/junit/junit/4.8.1/junit-4.8.1.jar:target/jar_contents/:. org.junit.runner.JUnitCore TempTest
JUnit version 4.8.1
start TempTest
end TempTest
beforeAll
.in test code
afterAll
Time: 0.078
OK (1 test)