I've started using playframwork (scala) and I'm writing some tests.
Before starting them I'd like to put in some mock data in my db (mongo) and later on when the tests are over remove this data.
I've got the code to put/remove this data but can't figure out how to consistently get this done before/after the tests are run.
I'm using the "specs2" testing library that comes with playframework but was unable to find any docs on how this can be done with specs.
Do you know how this can be done with specs? or can recommend another well known testing lib for playframework that I should use instead of specs?
I did not test it, but from the doc, Specs2 seems to support the Before/After approach: http://etorreborre.github.io/specs2/guide/org.specs2.guide.Structure.html#Before%2FAfter
You can find some running examples here on GitHub. It's from a pet project of mine, written in Scala with the Play Framork version 2.1.0.
The keypart is the following:
"Application" should {
"work from within a browser" in {
running(TestServer(3333), HTMLUNIT) { browser =>
This starts up the Play application on port 3333. Before this you can add the code for your test fixtures etc.
If you want the sytem to assign a free port for the tests, you can have a look here.
Related
I have an app in Play 2.6 and Scala and I want to configure all my Action to return Future or not, or i could say, to be Action or Action.async by a config file. So I could configure my entire app to work in production or test environment.
I have no clue how to do that. Hpw can I start to study and implement it?
Thank you
I wonder if you're looking for something like this which would allow you to provide environment specific configuration values? Including how to use those values in your controller
That document also covers how to specify which application.conf to use via the command line.
My application needs to use mongodb for normal data storage and also to keep pretty large files. Hence I started with plugins for mongodb (for normal data storage) and gridfs (for large files).
I am using grails 2.3.4 and trying to figure out what is the issue with the plugins that are included for using both mongodb and gridfs.
I have been searching the entire internet (including stalkoverflow) to find out any plugins that co-exists but in vain. Because no matter I use what combination of the available plugins, it all shows errors saying compatibility issues.
I am using the driver mongo-java-driver-2.11.3.jar
I ended up trying all plugins currently available. My build-config file looks like this:
<<<
// compile ":mongodb:1.3.3"
// compile ":mongodb:1.0.0.GA"
// compile ":gorm-mongodb:0.5.4"
// compile ":zk-mongodb:1.1-M1"
compile ":mongodb-morphia:0.8.2"
compile ":mongo-file:1.1.1"
// compile ":mongodb-gridfs:0.5.beta"
>
I know that I am missing something here.
Has anybody used grails2.3.4 and mongodb with gridfs ?
Please help me out either by pointing the correct plugins or sending code snippets of working samples.
Thank you all in advance.
I had a similar problem when I used ":mongodb-gridfs:0.5.beta" as well. In fact, even when I tried to remove the plugin (via my IDE) it continued to error. I deleted plugins.mongodb-gridfs=0.5.beta from application.properties, and then my application could build again.
You shouldn't need a separate plugin to use GridFS, it's actually part of the MongoDB Java driver. You will, however, need to get to the lower-level API instead of using the default Grails GORM stuff - there's some info on how to do this here.
The GridFS API works in a slightly different way to the rest of the driver, but here's an example. To create the GridFS to work with, you'll need something like new GridFS(mongo.getDB(databaseName)).
I don't have a fully working example to show you, but I hope you can piece together what you need from those different examples.
I've been using webfs which has worked very well for us in the past. It's a lightweight grails plugin for managing files using Mongo's gridfs. See https://github.com/dlaidlaw/mongo-web-filesystem for more details.
I use the webfs plugin in our document management module for managing any type of documents, up to 250MB in size. Am using mongodb:1.2.0.
I've not tested it with Grails 2.3.4, but it works on 2.0, 2.1 and 2.2.
I've a command line Java program that uses multiple folders containing files representing models, indices and resources that are loaded and used by some of the Java classes at runtime.
I'm trying to convert this program to a Play application (Scala) to provide a RESTFul interface. My question where should I put these folders so that they will be accessible by the Java classes when my Play application is running?
I'm using play-2.1.4.
you can add folder to classpath via SBT ( check out sbt document ),
so playframework can find you class, and then create some play action to reuse the service which you already have.
and, if you just want to wrap your application to provide some REST API, I'd like to recommend Spray to you, which can make your application export as REST API more easy. Hope this helps.
So I'm trying out this new TDD thing (about time haha). Anyways I have two unit testing files currently one for application and one for logic. The application logic test was autogenerated by xcode and when I go to manage schemes I can see the (void)testExample but I can't see the other tests I have created in my logic file, nor are they being run. Attaching picture.
Well it would help to read the docs a bit more carefully: http://developer.apple.com/library/ios/#documentation/DeveloperTools/Conceptual/UnitTesting/03-Writing_Test_Case_Methods/writing_tests.html#//apple_ref/doc/uid/TP40002143-CH4-SW1
You just have to prepend your methods with 'test'.
i.e.
-(void)testmynewcase {
}
I would like to be able to run a set of unit tests by linking to them in my application (e.g. I want to be able to click on a link and have it run a set of jUnit tests). The problem is that GWT and jUnit don't seem to be designed for this capability -- only at build time can you run the tests it seems.
I would like to be able to include my test code in my application and, from onModuleLoad for example, run a set of tests.
I tried to just instantiate a test object:
StockWatcherTest tester = new StockWatcherTest();
tester.testSimple();
but I get:
No source code is available for type com.google.StockWatcher.client.StockWatcherTest;
even though I include the module specifically.
Would anyone know a way to do this? I just want to be able to display the test results within the browser.
If you are trying to test UI elements in GWT using JUnit, unfortunately you may not do so. JUnit testing is limited to RPC and non-UI client-side testing. See this thread for a great discussion on what you can and cannot do with GWT jUnit testing.
If you are not trying to test UI elements, but are instead trying to inject your RPC code or client-side logic with test values (hence why you want to be able to click on a link and run a set of JUnit tests), then you should follow the following guide from testearly.com: Testing GWT with JUnit. In short, you should make sure that the method you are testing does not include any UI elements and if the method you are testing is asynchronous in nature, you must add a timer.
In 2.0, HTMLUnit was added. You may wish to use this instead of firing up a browser each time you wish to test.