Scala test cannot find any test to run - scala

I am trying to run some test in scala play framework. Here is the code that I have written
package com.sentrana.mmcore.integrationTests
import org.specs2.mutable._
import org.specs2.runner._
import org.junit.runner._
import play.api.test._
import play.api.test.Helpers._
import play.api.libs.json._
class ApplicationSpec extends Specification with Tags {
"Application" should {
"work" in new WithApplication {
route(FakeRequest(GET, "/boum")) must beNone
}
}
}
This is the command that I am using to run the test -
test-only com.sentrana.mmcore.integrationTests.ApplicationSpec
I am not getting any error. But it is showing me that 0 tests have been.

If you add you test using IntellijIDEA make sure that the file has .scala extension. The IDE does not show errors but the activator cannot find the test because it is searching for scala files.

Related

import java classes into jsp project in eclipse

I have a jsp project and I am using eclipse. I want to import a couple of external java source code into Java Resources src. Is there a way to do it rather than create a couple of new classes and then copy and paste the code into it? Thank you.
If they're already in the expected package layout for source files, you can just File|Import from the Filesystem.
Actually nobody is getting what if one havn't define package ???
then define package in ur java code as :-
package MyPackage;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.*;
import java.util.Map.Entry;
public class NavBackend {
static boolean isNumeric(String str)
{
..............
..............
then in your jsp file you can write like :
<%#page import="MyPackage.NavBackend"%>

ScalaTest Plus not recognizing tests

I've been tasked to update and write a series of tests on an app in Scala Play, a language and framework I'm unfamiliar with. Part of what I'd like to do is integrate the ScalaTestPlus library. To get started I have been following the following tutorial:
https://www.playframework.com/documentation/2.2.x/ScalaTestingWithScalaTest
Unfortunately I am not getting very far. I have added a new unit test file to the tests folder:
import org.scalatestplus.play._
class StackSpec extends PlaySpec {
"A Test" must {
"pass" in {
assert(1 == 1)
}
"Fail" in {
assert(1 != 1)
}
}
}
and I have updated my build.sbt to include the scalatestplus library
"org.scalatestplus" % "play_2.37" % "1.2.0" % "test"//,
Using Activator, I am trying to run my test file with test-only. Everything compiles without errors, but activator is not finding any tests
[info] No tests were executed.
I don't believe the issue is with activator, since I can run old test files (from the previous engineer) using the test and test-only commands. A quick sample of one of the previous (working) test files:
import java.util.concurrent.TimeUnit
import com.sun.xml.internal.bind.v2.TODO
import scala.collection.JavaConverters._
import controllers.Application
import models.{Item, PriorityBucket}
import play.api.test._
class WebSpec extends PlaySpecification {
"Home page" should {
"do something" in new WithSeleniumDbData(TestUtil.testApp) {
Redacted.deleteAll()
val ObId = TestUtil.create(Some(PriorityBucket.Low),
Some(Application.ENGLISH))
val item = Item.find(ItemId).get
browser.goTo("/")
browser.await().atMost(2,
TimeUnit.SECONDS).until(Selectors.all_obs).isPresent
}
Any ideas where I've gone astray? Thanks in advance for the help!
I am using scala 2.11
I am using play 2.3.7
EDIT: Possibly relevant, I switched the extension from PlaySpec to FlatSpec and saw the following error when compiling:
SampleSpec.scala:10: value in is not a member of String
[error] "pass" in {
I made sure to import FlatSpec as well, which has me a bit confused--is FlatSpec a member of ScalaTest but not a member of ScalaTestPlus, I don't see why else the compilation would fail.
UPDATE: To further investigate the issue I spun up a brand new Play app and copied over my sample test. After some tooling around with versions I've been able to get my test to run on the activator test command with the rest of the suite. Unfortunately, any other commands like test-only are still returning no tests run.
For those following I ran across the issue...the class name in this case needed to be identical to the file name, otherwise test-only cannot locate it.

Error in compilation of scala file in play

I have a Scala file and I am using Play Framework 2.0.4 to compile it. Here is a part of it
import play.api.templates.Html;
import play.api.templates.Txt;
import securesocial.controllers.Registration.RegistrationInfo;
import securesocial.controllers.TemplatesPlugin.
import securesocial.core.{SecuredRequest, SocialUser};
import play.api.data.Form;
import securesocial.core.Identity;
import securesocial.core.SecureSocial._;
import securesocial.controllers.PasswordChange.ChangeInfo;
At compile time I get this error
identifier expected but 'import' found.
What is the issue here?
Could it be import securesocial.controllers.TemplatesPlugin.: the trailing dot?
Either remove the dot or make it import securesocial.controllers.TemplatesPlugin._

Problem when importing package in scala

Suppose I have such packages:
package test
package test.views
package test.others
package views
Now in a scala file, I want to import test._ and views._(not test.views._), so I write:
import test._
import views._
But when I use some classes under views._, it reports type xxx not found, unless I change views package to another name.
What should I do now?
You can switch package import order (theoretically it should work):
import views._
import test._
Or you can be more precise in views import:
import _root_.views._
Here's yet another way (though using _root_ is the surest way to go):
import test.{views => testviews, _}
import views._

Scala, importing class

I have two files:
logic.scala and main.scala
logic.scala contains one class and main.scala have one class with method main (to run it). And I want to import a class from logic.scala and use this class to create object(s) and work with them.
How to import and compile it in proper way?
logic.scala code
package logic
class Logic{
def hello = "hello"
}
main.scala code
package runtime
import logic.Logic // import
object Main extends Application{
println(new Logic hello) // instantiation and invocation
}
compile the files with scalac
scalac *.scala
run your application with scala
scala -cp . runtime.Main