How to unit test Dart in Phpstorm - unit-testing

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

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.

phpunit tests returning no assertions and all errors

I am new to unit testing (and would really like to learn). I tried pulling down this repository (https://github.com/serbanghita/Mobile-Detect) and have been trying to run their unit tests they already have set up. I have it to the point where phpunit is running but when I run
phpunit tests
from the root directory I get:
Tests: 1411, Assertions: 0, Errors: 1411
I have tried running
phpunit --configuration tests/phpunit.xml
but then I get the error:
Class "JohnKary\PHPUnit\Listener\SpeedTrapListener" does not exist
They have something in their documentation about running:
php phpunit.phar -c tests/phpunit.xml
but I get the error
Could not open input file: phpunit.phar
which is because of the way I have phpunit set up I'm sure...
Any suggestions on how to further trouble shoot this?
It appears you have configured https://github.com/johnkary/phpunit-speedtrap to be used as a test listener in your phpunit.xml but have not (properly) installed this extension.
And if your PHP cannot find phpunit.phar then you are either not pointing it to the correct path or you have not downloaded / installed the PHPUnit PHAR, maybe because you chose to install PHPUnit via Composer. In that case the correct path would be vendor/bin/phpunit, of course.

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.

netbeans cakephp unittest PHP Fatal error: Class 'App' not found in {filename} line 3

I am trying to run unit test from netbeans but it fails with this error.
PHP Fatal error: Class 'App' not found in /home/user/cakephp/app/Test/Case/Model/AceScoreTest.php on line 3
Stack trace:
1. {main}() /usr/bin/phpunit:0
2. PHPUnit_TextUI_Command::main() /usr/bin/phpunit:46
3. PHPUnit_TextUI_Command->run() /usr/share/php/PHPUnit/TextUI/Command.php:129
4. PHPUnit_Runner_BaseTestRunner->getTest() /usr/share/php/PHPUnit/TextUI/Command.php:150
5. ReflectionMethod->invoke() /usr/share/php/PHPUnit/Runner/BaseTestRunner.php:124
6. NetBeansSuite::suite() /usr/local/netbeans-7.2.1/php/phpunit/NetBeansSuite.php:0
Unit test works fine when run from the command line as
./cake test app Model/AceScore
What do I need to do to get cakephp unit test to work in Netbeans?
There must be some way to tell phpunit to look for App.php in lib/Cake/Core/App.php
Thanks.
Perhaps, you have to create a bootstrap file for PHPUnit and set it to NetBeans.
I have added new Action (PHPUnit Test Init Action[1]) to CakePHP pluign for NetBeans[2].
If you are using this plugin, please try it ;) Please see [1] about bootstrap file.
[1] https://github.com/junichi11/cakephp-netbeans#phpunit-test-settings-phpunit-test-init-action
[2] http://plugins.netbeans.org/plugin/44579/php-cakephp-framework

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.