Is dusk is mandatory to write phpunit test cases?how to write phpunit test cases in laravel 5.4? - unit-testing

I am newbie to laravel. I am using laravel 5.4 version, we have requirement of writing phpunit test cases for our application, So I have searched for writing phpunit testcases and also read the documentation in laravel website. I read about the 'dusk' feature for doing the browser tests. So, I have a doubt that is "Is the dusk is mandatory for writing the phpunit test cases in laravel 5.4? I also tried to install the 'dusk' package into our application but it is not getting installed after I run the command "composer require laravel/dusk".
below is the error that I am getting on command prompt:
c:\xampp\htdocs\ourappname>composer require laravel/dusk
using version ^1.1 for laravel/dusk
./composer.json has been updated
Loading composer repositories with package information
Updating dependies (including require-dev)
Package operations: 2 installs, 4 updates, 9 removals
- Removing maatwebsite/excel (2.1.17)
- Removing phpoffice/phpexcel (1.8.1)
- Removing jeremeamia/superclosure (2.3.0)
- Removing symfony/polyfill-php56 (v1.3.0)
- Removing symfony/polyfill-util (v1.3.0)
- Removing guzzlehttp/guzzle (6.2.3)
- Removing guzzlehttp/psr7 (1.4.2)
- Removing psr/http-message (1.0.1)
- Removing guzzlehttp/promises (v1.3.1)
- Updating psy/psysh (v0.8.3 => v0.8.5): Loading from cache
- Updating swiftmailer/swiftmailer (v5.4.7 => v5.4.8): Loading from cache
- Updating sebastian/diff (1.4.1 => 1.4.2): Loading from cache
- Updating laravel/framework (v5.4.21 => v5.4.23): Loading from cache
- Installing facebook/webdriver (1.4.1): Loading from cache
- Installing laravel/dusk (v1.1.0): Loading from cache
Writing lock file
Generating autoload files
> Illuminate\Foundation\ComposerScripts::postUpdate
> php artisan optimize
[Symfony\Component\Debug\Exception\FatalThrowableError]
Class 'Maatwebsite\Excel\ExcelServiceProvider' not found
Script php artisan optimize handling the post-update-cmd event returned with error code 1
Installation failed, reverting ./composer.json to its original content.
c:\xampp\htdocs\ourappname>
Anyone please tell me how to fix it? and also what is the process for writing the test cases in laravel 5.4? should we use 'dusk'? or any other way to do it? Thanks.

No, Dusk is not required to do unit testing. You can just use the basic tests.
Your error is related to when you installed the Excel package on your application; the Service Provider was added to your config/app.php, but now that you've removed the package from your application ("Removing maatwebsite/excel (2.1.17)") you also need to remove the Service Provider.

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?

Pabot - Unable to run parallel robotframework tests

So, I'm working on a robotframework test project, and the goal is to run several test suites in parallel. For this purpose, pabot was chosen as the solution. I am trying to implement it, but with little success.
My issue is: after installing Pabot (which, I might say, I did by cloning the project and running "setup.py install", instead of using pip, since the corporate proxy I'm behind has proven an obstacle I can't overcome), I created a new directory in the project tree, moved some suites there, and ran:
pabot --processes 2 --outputdir pabot_results Login*.robot
Doing so results in the following error message:
2018-10-10 10:27:30.449000 [PID:9676] [0] EXECUTING Suites.LoginAdmin
2018-10-10 10:27:30.449000 PID:400 EXECUTING Suites.LoginUser
2018-10-10 10:27:30.777000 PID:400 FAILED Suites.LoginUser
2018-10-10 10:27:30.777000 [PID:9676] [0] FAILED Suites.LoginAdmin
WARN: No output files in "pabot_results\pabot_results"
Output:
[ ERROR ] Reading XML source '' failed: invalid mode ('rb') or filename
Try --help for usage information.
Elapsed time: 0 minutes 0.578 seconds
Upon inspecting the stderr file that was generated, I have this message:
Traceback (most recent call last):
File "C:\Python27\Lib\site-packages\robotframework-3.1a2.dev1-py2.7.egg\robot\running\runner.py", line 22, in
from .context import EXECUTION_CONTEXTS
ValueError: Attempted relative import in non-package
Apparently, this has to do with something from the runner.py script, which, if I'm not mistaken, came with the installation of robotframework. Since manually modifying that script does not seem to me the optimal solution, my question is, what am I missing here? Did I forget to do anything while setting this up? Or is this an issue of compatibility between versions?
This project is using Maven as the tool to manage dependencies. The version I am running is 3.5.4. I am using a Windows 10, 64bit system; I have Python 2.7.14, and Robot Framework 3.1a2.dev1. The Pabot version is 0.44. Obviously, I added C:\Python27 and C:\Python27\Scripts to the PATH environment variable.
Edit: I am also using robotframework-maven-plugin version 1.4.0.8, if that happens to be relevant.
Edit 2: added the error messages in text format.
I believe I've come across an issue similar when setting up parallel execution on my machine. Firstly I would confirm that pabot is installed using pip show robotframework-pabot.
Then you should define the directory your results are going to using -d.
I then modified the name of the -o to Output.xml to make it easy to identify.
This is a copy of the code I use. Runs optimally with 8 processes
pabot --processes 8 -d results -o Output.xml Tests
Seems that you stumbled on a bug in the prerelease version of robot framework (3.1a2.dev1).
Please install a release version of robot framework. For example 3.0.4.
Just in case anyone happens to stumble upon this issue in the future:
Since I can't use pip, and I tried a good deal of workarounds that eventually made things more unstable, I ended up saving my project and removing everything Python-related from my system, so as to allow me to install everything from scratch. In a Windows 10, 64bit system, I used:
Python 2.7.14
wxPython 2.8.12.1, win64, unicode, for py27
setuptools 40.2.0 (to allow me to use the easy_install command)
Robot Framework 3.0.4
robotremoteserver 1.1
Selenium2Library 3.0.0
and Pabot version 0.45.
I might add that, when installing the Selenium2Library the way I described above, it eventually tries to download some things from the pip repositories - which, if you have a proxy, will cause you trouble. I solved this problem by browsing https://pypi.org/simple/selenium/, manually downloading the 2.53.6 .tar.gz file, then extracting it and running setup.py install on the command line.
PS: Ideally, though, anyone should be able to use proxy settings from the command line (--proxy http://user:password#server:port) to get pip and then use it; however, for some reason, probably related to network security configurations that I didn't want to lose time with, this didn't work in my case.

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.

Error testing Polymer Dart components

I'm having trouble getting any of my Polymer Dart tests to run due to the following error that appears after I run pub run test --pub-serve=8081 -p chrome
00:18 +1 -2: compiling test\markdone_test.dart
Failed to load "test\markdone_test.dart": Reflecting on type 'TodoInput' without capability
dart:_internal wrapException
TodoInput is one of the Polymer Dart components for this project, but I've gotten the same error on other projects I have tried testing.
I have followed the documentation on the pub package for dart-lang/test:
Added listorder_test.dart and listorder_test.html with x-dart-test referencing my dart file
Added an entrypoint under the polymer transformer for test/listorder_test.html
Added the test/pub_serve transformer with $include: test/**_test{.*,}.dart
Am I missing some setup step or annotation/metadata? I've been over the docs for testing and they really only have the one mention of testing Polymer components without much else.

Can no longer run my ember app locally in Windows 7

I did my first development in a Win7 machine, then switched to a Mac when I got that, which was great due to the speed of building with ember server running. I've been keeping everything in a Git repo. Everything works fine running ember server from my Mac.
Now, when I do a fresh clone from the repo on my Win7 computer, then do npm install and bower install (both of which complete fine), when I run ember server next, I get a bunch of errors saying ENOTEMPTY, directory not empty (path, blah blah blah).
It's complaining about some folder in the tmp directory, which the server command is creating and putting stuff into all by itself, so I don't know what it's complaining about.
I've been finagling with this about 5 different times now, but without success.
Ember CLI version is 0.1.1
Ember version is 1.6
Here's an example of one of the errors, but they're all similar (and similarly unhelpful):
ENOTEMPTY, directory not empty 'c:\Dev\star\tmp\remover-tmp_dest_dir-sRc08q1q.tm
p\templates'
Error: ENOTEMPTY, directory not empty 'c:\Dev\star\tmp\remover-tmp_dest_dir-sRc0
8q1q.tmp\templates'
at Object.fs.rmdirSync (fs.js:623:18)
at rmkidsSync (c:\Dev\star\node_modules\ember-cli\node_modules\rimraf\rimraf
.js:247:11)
at rmdirSync (c:\Dev\star\node_modules\ember-cli\node_modules\rimraf\rimraf.
js:237:7)
at fixWinEPERMSync (c:\Dev\star\node_modules\ember-cli\node_modules\rimraf\r
imraf.js:150:5)
at Function.rimrafSync [as sync] (c:\Dev\star\node_modules\ember-cli\node_mo
dules\rimraf\rimraf.js:216:26)
at Remover._remove (c:\Dev\star\node_modules\ember-cli\node_modules\broccoli
-file-remover\index.js:46:10)
at c:\Dev\star\node_modules\ember-cli\node_modules\broccoli-file-remover\ind
ex.js:60:14
at Array.forEach (native)
at c:\Dev\star\node_modules\ember-cli\node_modules\broccoli-file-remover\ind
ex.js:59:12
at $$$internal$$tryCatch (c:\Dev\star\node_modules\ember-cli\node_modules\rs
vp\dist\rsvp.js:470:16)
file added bootstrap.min.js
file added favicon.ico
file added sb-admin-2.js
Okay, I managed to do something that worked. I had forgotten I needed to disable Windows Indexing on my tmp folder at least (I did it for the whole cloned project):
Windows Key, type "Indexing Options"
Click the drive, then Modify
Uncheck places you don't want indexed (like the tmp folder)
If you use Sublime, go to Perferences --> Settings - User and add the following:
"folder_exclude_patterns":
[
"tmp/*",
],
Finally, I just had to keep doing ember server, stopping it, and doing it again until it build successfully (took around 5 tries).