Groovy problem (package keyword seen as invalid token) with test using archetype generated by maven - unit-testing

I'm trying to launch the tests of the groovy simple archetype generated by maven:
mvn archetype:generate
-DarchetypeGroupId=org.codehaus.gmaven.archetypes
-DarchetypeArtifactId=gmaven-archetype-basic -DarchetypeVersion=1.3
But when I launch the ExampleTest.groovy in src/test/groovy/fr/xlim/ssd/fuzzer/ExampleTest.groovy:
import Example
package fr.xlim.ssd.fuzzer
class ExampleTest extends GroovyTestCase
{
void testShow() {
assert true
new Example().show()
}
}
I've the following error:
unexpected token: package - file:/home/kartoch/works/groovy/fuzzer
/src/test/groovy/fr/xlim/ssd/fuzzer/ExampleTest.groovy[3:1]
It seems the package keyword is badly placed or not recognized by the groovy compiler, even if the test file is in the correct directory.
Any ideas ? maybe a syntax changes in Groovy (I'm using groovy 1.7) ?
Note: this error may not be related to maven

Move your import under the package line, just as in Java.

Related

Looking for documentation setup jest for unit test of admin plugin

my project was created with the swdc create-project ...
Is there a documentation, a tutorial or description for the right setup/configuration unit testing with JEST for custom plugin in administration?
This tutorial describes only how to write a test
But i think there must be a official setup documentation because of versions etc.
EDIT: a tutorial with code is now avialable
Using the suggested solution and execute the test, throws an configuration error:
● Test suite failed to run
Configuration error:
Could not locate module src/core/factory/module.factory mapped as:
undefined/src$1.
Please check your configuration for these entries:
{
"moduleNameMapper": {
"/^src(.*)$/": "undefined/src$1"
},
"resolver": undefined
}
...
Cause of error:
process.env.ADMIN_PATH not setted but required in %Project%/custom/plugins/%MyPlugin%/src/Resources/app/administration/node_modules/#shopware-ag/jest-preset-sw6-admin/jest-preset.js
My solution:
set process.env.ADMIN_PATH in %Project%/custom/plugins/%MyPlugin%/src/Resources/app/administration/jest.config.js
// jest.config.js
...
const { join, resolve } = require('path');
process.env.ADMIN_PATH = resolve('../../../../../../../src/Administration/Resources/app/administration');
...
I think it is easiest to just copy and adapt from a plugin that already has jest tests set up. Look at the administration directory for SwagPayPal for example. Copy the dependency and script sections from their package.json. Also copy the entire jest.config.js. Then within the administration directory of your plugin you should be able to npm install followed by npm run unit or npm run unit-watch and it should find *.spec.js files within the test sub-directory.

How to exclude tagged tests in Gradle Kotlin Build Script?

Having the following task registered in a gradle build script:
tasks.register<Test>("unitTest") {
useJUnitPlatform {
excludeTags("integrationTest")
}
}
And the tests tagged with
import org.junit.jupiter.api.Tag
#Tag("integrationTest")
class MyIntegrationTest {
...
}
./gradlew unitTest still does run the tagged integration-test as well, I tried several other options provided by the gradle documentation to exclude the integration tests, though nothing seemed to work by now.

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.

How to unit test Dart in Phpstorm

I installed the dart plugin, set the SDK home path to the dart-sdk folder, configured the scope and checked the 'Dart SDK enabled' option in Phpstorm 6.0.3. Next, I created a dart file in a 'test' directory with the following code (obviously I added the dependency unittest in my pubspec.yaml and ran pub get):
library mytests;
import 'package:unittest/unittest.dart';
main(){
test('my test', (){
expect(1+1, equals(2));
});
}
When I run this unit test however (by right clicking inside the file and selecting 'Run Test: my test', an error is outputted in the unit testing window stating the following:
C:/dart/dart-sdk/bin/dart.exe --ignore-unrecognized-flags --package-root=C:/Users/myname/dart/pokerdart/test/packages/ C:\Users\myname\AppData\Local\Temp\jetbrains_unit_config.dart
Testing started at 18:55 ...
'file:///C:/Users/myname/AppData/Local/Temp/jetbrains_unit_config.dart': error: line 1 pos 1: unresolved implicit call to super constructor 'Configuration()'
import 'package:unittest/unittest.dart';
^
When I run the test using powershell it just works... Am I missing something/doing something wrong?
Any help is greatly appreciated!
WEB-9636 is fixed in version 7. Please try upgrading to PHPStorm 7.1.3. Or, even better, try PHPStorm 8 EAP (http://confluence.jetbrains.com/display/PhpStorm/PhpStorm+Early+Access+Program) - Dart support has been improved there

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.