phpunit tests returning no assertions and all errors - unit-testing

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.

Related

Vue CLI plugin to add Jest test runner doesn't transpile .js files

Just a quick disclaimer, I cannot reproduce this on another project, which is why I'm here instead of making an issue on the Github.
Issue
So a quick demo project I made to show a co-worker how to use the Vue test utils, went off the wagon. It doesn't get picked up in the transform part of the jest.config.js.
I made the project with the Vue CLI, using vue create demo-project choosing ESlint and Babel, then running vue add #vue/cli-plugin-unit-jest. Everything went fine, I committed, ran the test command and everything went fine.
So we started testing snapshots, and everything was fine. Next day, come back to the project to keep going, and this is the error I get.
> vue-jest#0.1.0 test:unit .../demo-projects/vue-jest
> vue-cli-service test:unit
FAIL tests/unit/example.spec.js
● Test suite failed to run
Jest encountered an unexpected token
This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.
By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".
Here's what you can do:
• To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
• If you need a custom transformation specify a "transform" option in your config.
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/en/configuration.html
Details:
.../demo-projects/vue-jest/tests/unit/example.spec.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import { shallowMount } from '#vue/test-utils';
^
SyntaxError: Unexpected token {
at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:403:17)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 1.163s
Ran all test suites.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
Just running the normal npm run test:unit results in the example.spec.js that comes with the test utils is not babel'ed, and fails in the Node test environment.
Attempted Solutions
Did not work
Deleting node_modules and reinstalling
Deleting package-lock.json, in addition to the above step ( separately done )
Reverting back to the commit when it was working
Checking out to a different branch, deleting all the files that vue add #vue/cli-plugin-unit-jest added, then running the command again to re-create all the files
jest.config.js
tests/ - and all it's files
Worked
Pretty clear what's happening, so in the jest.config.js file, I added the .js file under the transform field.
transform: {
'^.+\\.vue$': 'vue-jest',
'.+\\.(css|styl|less|sass|scss|svg|png|jpg|ttf|woff|woff2)$': 'jest-transform-stub',
'^.+\\.(js|jsx)?$': 'babel-jest' // added .js
},
This solution solves the problem, and properly transforms the example.spec.js
Attempted Recreation
I tried to see if this was a bug by creating another project, running the same steps and it worked just fine. I even copied and pasted all the files from the broken one to the new one, looking for differences in git. It was exactly the same. Which is why I thought it might be node_modules, but it still didn't work.
Uhh
Hopefully this isn't a waste of time for anyone reading since it's not truly a problem. I mainly wanted to have it for anyone who might have the same issue to see that adding the .js extension would solve the problem without having to start over, but also curious if anyone has insight on why this might be happening?

Running Calabash Android from Rubymine

Can someone post some help. I have tried different config but can't run Calabash Android tests from within Rubymine. Works on Terminal though.
Finally found the solution after some trial and error. Here is what you need to do on Rubymine:
EDIT Runner Options and add: APP_PATH= "" and TEST_APP_PATH="" and run the feature file. This should do it.
Thanks,
Method, suggested by Manpreet Singh, uses cucumber as the test runner. Here you need to define APP_PATH and TEST_APP_PATH environmental variables:
APP_PATH will need to be reset if apk file or file name changes (e.g. uploaded a new version of the apk)
TEST_APP_PATH points to the test server file, which is generated by calabash when you try to connect calabash to your new apk for the first time (e.g. with "calabash-android run" or "calabash-android console"), or if previous test server file was deleted
This way it's easier to create a new test using "Right-click on a scenario or feature file > Create configuration" in RubyMine thanks to its robust cucumber support
Another method is, as pointed by Dave, to set up a calabash-android run as a gem executable - see this thread for details.
Need to set apk path only
This way, your execution is the same as in the command line and passing arguments (such as cucumber profile, output options etc) will work for sure. Also, such configuration is less fragile to the test_server change. However, it's a bit more cobersome to setup than as a cucumber run.
After all with the current architecture of calabash, I still prefer to code in IDE but run in the command line :) IDE becomes very useful, when you need to debug tests.
the setting above does not work for me
here is the setting worked. basically, in Run/Debug configureation, need to create a Gem command to execute calabash-android, and correct arguments, not a configure for Cucumber .
http://daedalus359.wordpress.com/2013/11/02/getting-calabash-to-play-nicely-with-rubymine/
-dave

getting this error: unrecognized option --skeleton-test using PHPUnit 3.7.10 using Netbeans 7.1.2

I have installed PHPUnit via pear installer - but I'm having trouble getting it to work get this error when using Tools> Create PHPUnit Tests
The output error is: PHPUnit 3.7.10 by Sebastian Bergmann. unrecognized option --skeleton-test
This is the Unit Testing tab in Netbeans:
Tried different include paths in the General Tab but not sure how to include the classes
Any ideas what is wrong...? thanks
Verify that the phpunit-skelgen file exists in the same directory as the phpunit binary (C:\wamp\bin\php\php5.3.5\ in your installation).
If not, install the PHPUnit SkeletonGenerator the same way you installed PHPUnit, eg from PEAR:
C:\wamp\bin\pear.exe install phpunit/PHPUnit_SkeletonGenerator

PHPUnit + Symfony does nothing

I just installed PHPUnit on OS X + MAMP. (My phpunit was installed in my MAMP folder, so I copied it to /usr/bin because I couldn't use the "phpunit" command in terminal without the path)
New Symfony folder
When I go to a new Symfony2 folder and I try phpunit -c App/the tests start and I get a green confirmation that all tests passed.
PHPUnit 3.7.8 by Sebastian Bergmann.
Configuration read from
/Users/username/Dropbox/www/symfonydev/Symfony/App/phpunit.xml.dist
.
Time: 0 seconds, Memory: 15.50Mb
OK (1 test, 1 assertion)
Own symfony website
But when I go to my own little Symfony2 project and execute the same command, nothing happens! He doesn't even load the phpunit.xml.dist. I get no output at all on my terminal window.
The test file, however, does exist and is readable, I can start it by explicitly specifying it on the command line of phpunit:
phpunit -c app/ src/MatchTracker/Bundle/Tests/Controller/AuthenticationControllerTest.phpand this works.
It seems that something is wrong with the phpunit.xml.dist. It's the default phpunit.xml.dist and I tried renaming it to phpunit.xml. But nothing happens. What could be the problem? I think he can't find my xml or use it, or maybe he can read the phpunit.xml but doesn't find my tests.
Here's an example from my terminal: You see that the phpunit command doesn't do anything, except when I specify the test file...
MacBook-Pro:www username$ ls
LICENSE app composer.json composer.lock composer.phar src vendor web
MacBook-Pro:www username$ ls app/
AppCache.php SymfonyRequirements.php cache console phpunit.xml.dist
AppKernel.php autoload.php check.php logs
Resources bootstrap.php.cache config phpunit.xml
MacBook-Pro:www username$ phpunit -c app/
MacBook-Pro:www username$ phpunit -c app/ src/MatchTracker/Bundle/Tests/Controller/AuthenticationControllerTest.php
PHPUnit 3.7.8 by Sebastian Bergmann.
Configuration read from /Users/username/Dropbox/www/matchtracker.be/www/app/phpunit.xml
F
Time: 1 second, Memory: 21.75Mb
There was 1 failure:
1) MatchTracker\Bundle\Tests\Controller\DefaultControllerTest::testIndex
Failed asserting that 404 matches expected 200.
/Users/username/Dropbox/www/matchtracker.be/www/src/MatchTracker/Bundle/Tests/Controller/AuthenticationControllerTest.php:28
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
MacBook-Pro:www username$
What's in your phpunit.xml? <testsuites> section of this file tells phpunit which directories scan for tests.
Remember that phpunit.xml overwrites phpunit.xml.dist.
Look at the original phpunit.xml.dist file and either remove the phpunit.xml or start by copying phpunit.xml.dist into phpunit.xml.

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.