Groovy/Grails Unit Test Error with custom codec - unit-testing

I am having an issue with the "Getting Started with Grails" tutorial from the Grails website. It is having me create a custom codec in the utils directory. I have created the codec and it works in the application, however when I add the codec to my controller unit test, as the tutorial suggests, it fails. Here is the message I get when I run "grails test-app UserController -unit":
"No such property: SHACodec for class: racetrack.UserControllerTests"
I have tried using the loadCodec() method to include the codec, but got the same message.
Does anyone have any suggestions on how to resolve this unit test issue? If it's an import issue, what would the import path be for my SHACodec.groovy file if it is in the /grails-app/utils/?
My tutorial code is available for download at http://arlitt.com/racetrack.zip.

I ran into this too (working through the code in the Grails book).
What I found works is this: explicitly load the codec. You don't need to include it in your imports. Make sure that the SHACodec.groovy file is in the grails-app/utils directory.
The following code snippet shows you how I did it.
class UserControllerTests extends ControllerUnitTestCase{
protected void setUp() {
super.setUp()
loadCodec (org.codehaus.groovy.grails.plugins.codecs.Base64Codec)
loadCodec (racetrack.SHACodec)
}
// ...
}

Codecs are not automatically loaded, you need to load them.
Refer to this post for more details: http://kousenit.wordpress.com/2010/02/24/using-a-codec-in-a-grails-unit-test/

Related

can't import the test helper addon in ember-cli-mirage

Facing the same issue - https://github.com/miragejs/ember-cli-mirage/issues/1445
Uncaught Error: Could not find module project-name/tests/helpers/push-mirage-into-store imported from project-name/mirage/factories/addon
Initially got this error and tried #makepanic instructions
After that
Uncaught Error: Could not find module #ember/test-helpers imported from project-name/mirage/helpers/push-mirage-into-store
can you pls help here to resolve this.
I bet you are running into the error, which is described in this comment by makepanic in the GitHub issue you linked:
When running the app directly, the browser opens index.html which
isn't loading tests.js. This file contains everything related to
tests.
If you open tests/index.html, that will also load tests.js and add any
modules under tests/* to the loader registry.
This means without the tests file loaded, you can't import anything
from tests/*.
You are affected by that issue if you face it when running ember serve.
The comment also includes a possible solution:
With you moving the helpers to /mirage, they gets registered in both index.html and tests/index.html.
An alternative would be to disable mirage in all enrironments except for test. But that is only a feasible solution if you use mirage only for testing but not for development.

Where is HibernateTestMixin located in Grails 3?

I am trying to upgrade a Grails 2.5.1 application to Grails 3.0.5. When I try to run the tests I get a compiler error
/Users/xxx/dev/xxx/src/test/groovy/y/xxx/z/PricingSpec.groovy: 5: unable to resolve class grails.test.mixin.hibernate.HibernateTestMixin
# line 5, column 1.
import grails.test.mixin.hibernate.HibernateTestMixin
It seems that grails-plugin-testing does not include that Mixin. Can anyone tell me what dependency I am missing?
EDIT Same goes for grails.test.mixin.gorm.Domain
Have a look at HibernateTestMixin Basics.
You would need this dependency in build.gradle:
dependencies {
testCompile 'org.grails:grails-datastore-test-support:4.0.4.RELEASE'
}
You might not have noticed it but these mixin were already had been moved to grails-data-mapping in Grails 2.4.* apps
If you look closely in BuildConfig.groovy of a newly created Grails 2.4.* or 2.5.*, one would see the same dependency.

Unit testing Quartz plugin for Grails

I have some trouble writing the most basic unit test for a job. My problem can be recreated by creating a new job by running grails create-job my in the console.
This will create two files
MyJob.goovy (under the default package myApp - resides in test\unit\myApp)
MyJobSpec.groovy (under the default package myApp - resides in grails-app\jobs\myApp)
Now if i try to use the job MyJob in the test, as example
import myApp.MyJob //This is not resolved
#TestMixin(GrailsUnitTestMixin)
class MyJobSpec extends Specification {
def myJob
I get the compiler error Groovy:unable to resolve class MyJob. Everything so far was automatically created by the plugin. What is going on here? Is there something i did wrong / how do i get this to work?
Using grails 2.3.11.
I don't know which IDE are you using or if you are running everything on a terminal, but I had similar problems with Eclipse and what you need to do is to add grails-app/jobs to the classpath as a source folder.

Why `#import("dart:unittest")` can't run?

I write some dart test code:
#import("dart:unittest");
main() {
test('this is a test', () {
int x = 2+3;
expect(x).equals(5);
});
}
It doesn't display any error in dart editor, but when I press the "run" button, it reports:
Do not know how to load 'dart:unittest''file:///home/freewind/dev/dart/editor
/samples/shuzu.org/test/model_test.dart':
Error: line 1 pos 1: library handler failed
#import("dart:unittest");
^
I see there is a "dart:unittest" library in my dart-sdk. Why it can't be run?
Unfortunately, the unittest library is not yet wired into the dart: namespace. Until that happens, if it ever happens, you'll need to use a relative path to get to the unittest library.
Something like:
#import('path-to-dart/lib/unittest/unitest.dart');
More examples are here: http://api.dartlang.org/unittest.html
This page keeps showing up in Google results for dart and unittest, so I thought I would add an update. The unittest library is now installed quite easily through pub, Dart's package manager. To do this, make sure that you:
check Add pub support when you create a new Dart application.
Then add (or uncomment) the dependency for the unittest package in your pubspec.yaml file. That file should look like this:
name: range
description: A sample application
dependencies:
unittest: { sdk: unittest }
Run pub install (although if you are using Dart Editor, this command should automatically get run for you). Then, in the file where you will be writing your tests,
add this import declaration:
import "package:unittest/unittest.dart";
And you should be good to go.

Module unittest Kohana error, how to use?

I am trying times longer run it has several errors. Someone
has any tutorial or some way to make it work. Tested
several tutorials and I could not.
vlw staff
I already placed the php unittest unit in the directory.
the error is as follows:
Fatal error: main() [function.require]: Failed opening required
'PHPUnit/Util/Filter.php' (include_path='.;C:\php5\pear') in C:\wamp
\www\doeseulixo\branches\module_unittest\modules\unittest\PHPUnit
\Framework.php on line 0
See Installing PHPUnit.
PHPUnit should be installed with the 'pear' utility rather than downloaded manually. Kohana needs access to more than one class of the library.