Questions tagged [scalatest]
The Scala testing framework
1,569
questions
2
votes
0
answers
24
views
sbt val evaluated more than once
I'm creating a val into my build.sbt, made of a random string, to be used in the Setup and Cleanup methods for scalatest, like this:
val foo = Random.alphanumeric.take(3).mkString
...
Test / ...
0
votes
0
answers
27
views
Scala : print only during unit test
I want to display in the output window, but only during Unit tests and not during normal execution. I am using Scalatest for UT. Any idea how this can be handled in a clean way?
println("...
0
votes
0
answers
8
views
Mocking dataframe reader keep running at mockedReader.json(any())
i have a scala code that reads from json file and converts to dataframe.
while unit testing the code i wasnt able to figure out a way to mock the spark.read option.
val primary_topic_offset = spark....
0
votes
1
answer
30
views
Scala ZIO test assert an IO
I have a function with return type RIO as follows:
object Compresser {
val buffer = ZManaged.fromAutoCloseable(ZIO.succeed(new ByteArrayOutputStream()))
val stream = for {
b <- buffer
...
0
votes
0
answers
27
views
Unable to run spark-testing-base test with Spark v3.2.1
I was trying to run Spark UT with spark-testing-base and scalatest, getting following exceptions:
[error] sbt.ForkMain$ForkError: java.lang.IncompatibleClassChangeError: Expected instance not static ...
0
votes
1
answer
27
views
Eventually didn't tolerate unsuccessful attempts before giving up
I have a simple test case which is using TestActorRef and eventually to verify a timeout call of a method. Here is details of 3 file sources:
TestRestUtility.scala
import play.api.http.HttpVerbs
...
0
votes
0
answers
31
views
IntelliJ cannot find Scala integration test framework
I have configured a Scala project for integration tests as described in https://www.scala-sbt.org/1.x/docs/Testing.html.
I can get the integration tests executed from sbt, but not from IntelliJ. ...
1
vote
1
answer
34
views
When running "local-cluster" model in Apache Spark, how to prevent executor from dissociating prematurely?
I have a Spark application that should be tested in both local mode & local-cluster mode, using scalatest.
The local-cluster mode is submitted using this method:
How to scala-test a Spark program ...
0
votes
1
answer
28
views
All maven surefire reports are zero! How could this happen?
I have a scala project configured with maven surefire plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</...
0
votes
1
answer
32
views
Is it possible to mock multiple Scala Objects in the same test?
Say I have the following object I want to test
object ObjectToTest {
def apply() = {
val example = List.fill(5)(CaseClassExample("here", "there"))
ChildObject(example....
0
votes
0
answers
28
views
How to Unit Test Spark.Read in Scala
I wonder, how can I write the unit test case for below piece of code
val df = spark.read
.format("com.microsoft.sqlserver.jdbc.spark")
.option("url", [JDBCURL])
....
0
votes
1
answer
19
views
How to have scalatest/sbt report labelled cases from TableDrivenPropertyChecks
I am new to scalatest and a bit lost in the gigantic inconsistent mess of features
I am trying to write parameterized tests. It seems that the way to do that is via TableDrivenPropertyChecks
I managed ...
0
votes
0
answers
41
views
Unit tests run as scalatest in intellij but the same fails in build
I am using scalatest for unit testing my scala code with intellij, gradle, mockito.
There are few testcases which run absolutely fine when run as scalatests ,however fail when running as part of ...
1
vote
0
answers
52
views
Gradle 5.5 Caused by: groovy.lang.GroovyRuntimeException: Could not find matching constructor
With Gradle 5.5 and com.github.maiflai:gradle-scalatest:0.24 I am getting below exception
at com.github.maiflai.ScalaTestAction.makeAction(ScalaTestAction.groovy:68)
at com.github....
0
votes
0
answers
46
views
Scoverage with gradle
I have been trying to setup scoverage to run scalatests in gradle and generate report, however no luck.
Can someone help me with how to setup build.gradle file to run scalatests and generate the ...
1
vote
0
answers
24
views
IntelliJ not finding individual tests in scalatest FlatSpec
I am running IntelliJ. I have a test suite that extends FlatSpec like
class MyTest extends FlatSpec {
val foo = Seq(1, 2, 3)
foo.foreach { x => println(x) }
it should "run test 1"...
1
vote
0
answers
24
views
Java class created for tag annotation in scalatest giving duplicate class error
package com.mycompany.myproject.testing.tags;
import java.lang.annotation.*;
import org.scalatest.TagAnnotation
@TagAnnotation
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ...
0
votes
1
answer
41
views
Avoiding to instantiate object in test files
I have a Redis PubSub object:
object RedisPubSubService {
implicit val system = ActorSystem("RedisEtatyLib")
val config = ConfigFactory.load.getObject("redis").toConfig
val ...
0
votes
0
answers
20
views
Access configMap in a companion object in Scala
Based on the scalatest doc (https://www.scalatest.org/scaladoc/1.8/org/scalatest/ConfigMapWrapperSuite.html), you can pass an argument to the configMap like this:
@WrapWith(classOf[...
0
votes
0
answers
32
views
replace ClassName with custom string to display in IntelliJ scalatest window
For a specific use case, we are trying to replace
ClassName with Verifying ClassName
in IntelliJ scala test case window.
For that, we overridden toString method in spec class as below :-
override def ...
0
votes
0
answers
15
views
How to avoid re-using an existing SparkSession during ScalaTest runs
I get the warning
WARN SparkSession$Builder: Using an existing SparkSession; the static sql configurations will not take effect.
whenever I run tests which involve engaging a SparkSession.
I think ...
0
votes
0
answers
31
views
FileNotFoundException scala unit test fails in jenkins
I am testing fileNotFoundException when unit testing my scala code using scalatest in intellij.
The code runs fine in local but fails in jenkins build.
Below is the testcase.
test("fileNotFound&...
0
votes
1
answer
57
views
Cannot run 'mvn clean test' using scalatest
I'm learnning how to use ScalaTest.
now I'm using scala 2.11.8, in JetBrains IDEA.
Fisrt I wrote a simple trait traitA.
package Cha1_TraitsAndMixinCompositions.Clash
trait A {
def hello(): String = ...
0
votes
0
answers
122
views
Scala Test - Code with Await ignore the mocked future
I'm writing unit tests for a service method that returns a Future[Boolean].
Inside the code that I'm testing, there is an Await.result usage on a sequence of future.
class serviceLogic, method logic: ...
0
votes
0
answers
21
views
How to run Specs inside "Suites" in parallel in scalatest?
I have a Gradle project with some tests. These tests are directly written in Spec files.
I want to run subset of these specs in parallel (Test inside specs shouldn't run in parallel). So I created a ...
0
votes
0
answers
45
views
ArrayIndexOutOfBoundsException while reading from dataframe in scala
I'm working on scala streaming unit test but while reading from csv file getting ArrayOutOfBoundsException
Code :
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec....
0
votes
0
answers
35
views
IntelliJ 'A needed class was not found' for ScalaTest
I am currently trying to run some ScalaTest cases on my MongoEmbedDatabase following this documentation: https://github.com/SimplyScala/scalatest-embedmongo
My test code is pretty simple:
package com....
0
votes
1
answer
79
views
How to use ScalaTest Matcher to Test Failure Exception Type?
Given a scala function that can produces Failures:
def testableFunction(x: Int) : Try[Int] = {
if(x == 0)
Failure[Int](new IllegalArgumentException("0 is bad"))
else if(x == 1)
...
1
vote
1
answer
160
views
How to set SCALACTIC_FILL_FILE_PATHNAMES=yes (or other environment variable) for scalac from sbt?
I would like to use full paths in ScalaTest reporter. The value LineInFile.filePathname tells me I should:
Please set the environment variable SCALACTIC_FILL_FILE_PATHNAMES to yes at compile time to ...
0
votes
0
answers
27
views
Scalacheck stateful mutation testing with Pitest
Mutation testing of a stateful system with Scalacheck "Commands" are used in combination with the the mutation testing tool (plugin) Pitest.
We have a Java class "CarAlarmSystem.java&...
0
votes
0
answers
11
views
Running a JunitTest in Java using Scalatest.runner
I have a Junit Test written in java and i am using org.scalatest.tools.Runner to run. The JUnit Jar is in class path and here is my command.
./<batch file with java - classpath command> -j ...
0
votes
1
answer
77
views
pure java project with unit tests written using scalatest having compiler compatibility issue
We have a simple java project with unit tests written in scalatest:
no scala library in compile scope (autoScalaLibrary := false)
scala-compiler added to test scope to compile unit tests written in ...
5
votes
1
answer
104
views
ScalaTest: How to mix parallel and sequential tests
Say I have 6 test suites: A B C D E F, and I want A B C to run sequentially and THEN run D E F in parrallel.
With an output like that:
A
B
C // always in that order
E
D
F // The order doesn't matter
...
0
votes
1
answer
104
views
Scala Testing with Mock objects within objects
While Testing Called1.writeData and mocking using the traits, control is still going to the original implementation. Need help from experts.
object Caller1() {
def method1(param1:String, param2:...
0
votes
1
answer
146
views
Akka Http route test with formFields causing UnsupportedRequestContentTypeRejection
I have a GET request with parameters and a formField.
It works when I use a client like Insomnia/Postman to send the req.
But the route test below fails with the error:
...
0
votes
1
answer
83
views
Scalatest problem : value FunSuite is not a member of org.scalatest
I'm trying to write a test for my project in Scala 3. I added Scalatest library as :
libraryDependencies ++= Seq(
....
"org.scalatest" %% "scalatest" ...
0
votes
1
answer
36
views
how to check all the records in column having bigint type or not in scala, while writing unit test cases?
val types = for(i <- result) yield i.column_name.isInstanceOf[Option[BigInt]]
assert(result.forall(_.column_name.isInstanceOf[Option[BigInt]]
does it efficient enough?
can anyone share better ...
0
votes
1
answer
94
views
Sbt unable to find List class definition on Scala 3.0.0-M2
I have a scala project on SDK 16 using sbt on Intellij IDEA Ultimate. Here is my build.sbt file :
name := "meteo-france-client"
version := "0.1"
scalaVersion := "3.0.0-M2&...
0
votes
3
answers
430
views
Sbt not resolving Scalatest on Intellij IDEA
I know there are already answered questions about this, but they didn't work for me, maybe because they are too old now.
So I'm creating a scala project on Intellij IDEA Ultimate (SDK 16.0.1). I ...
0
votes
0
answers
42
views
scalatest and mockito: argumentmatchers.eq and any not working as expected
I am trying to stub a method in a mocked service in scalatest using mockito:
when(mockedModelService.update(ArgumentMatchers.eq(id1), ArgumentMatchers.eq(id2),
any[Model], ArgumentMatchers.eq(user)...
0
votes
0
answers
37
views
Scalatest and mockito: spy not working as expected
I am using scalatest+mockito for unit tests. I have set a spy on an object to check if target method is actually invoking another method or not.
"Find all modules" in { f =>
for {
...
3
votes
1
answer
68
views
Dynamicaly Created Tests sbt
I'm trying to dynamically run some basic tests in the following way (this is a pseudo code of my test, my actual tests are a bit more complicated):
class ExampleTest extends AnyWordSpec {
def ...
1
vote
0
answers
25
views
Running Regression Test Selection (RTS) for Scala (SBT) - Ekstazi/STARTS
Has anyone tried RTS tools like Ekstazi or STARTS to perform Regression test selection (RTS) for scala SBT (not maven) projects where tests are written using ScalaTests?
I tried by adding following ...
0
votes
0
answers
218
views
Gradle doesn't execute scalatests
I have created scalatest for my spark project and when I am running gradle task "test" then it doesn't execute a single test. It shows zero tests.
Even as part of the build process, gradle ...
0
votes
2
answers
73
views
scalatest matcher for Some(some long value)
I have following validation in scalatest based unit test:
response shouldBe Some(any[Long])
I just need to check that response is of type Some containing any long value.
But it fails as:
Expected :...
5
votes
0
answers
94
views
In scalatest, how to show full diff in test result?
When there is an equality assertion in scalatest that fails. It generally shows only the different part, e.g.:
"...error;
!I e: F[Arg]
[g invalid because
nonconformant bounds;
[Arg, Nothing]
[A &...
0
votes
0
answers
51
views
Mockito with scalatest: Mocking a method for multiple calls
I am trying to mock an object in scalatest using mockito. I have to mock a method multiple times. In java something like this works:
when(mockedObject.foo(anyString())).thenReturn(value1, value2)
But ...
0
votes
0
answers
42
views
Mocking circe HCursor,ACursor in scalatest
I am trying to mock HCursor,ACursor from circe library. I have 2 fields to unmarshall, one to plain string, other to Option of string. I have following code:
...
val hCursor = mock[HCursor]
val ...
0
votes
1
answer
157
views
Compiling scala file placed under resource folder and access it in test class
I have a project setup as:
Project
|__src
| |_main
| | |_src_file_1.scala
| | |_src_file_2.scala
| |
| |_resources
| |_resource_file_1.scala
|
|__test
|_test_file_1.scala
Source files ...
0
votes
1
answer
83
views
How to mock nested classes in scala
I have a class that can be simplified as below
class my {
val b = new subClass()
def a () = "not mocked"
class subClass {
def ret () = "not mocked"
}
}
I need some ...