How to debug Meteor unit test in WebStorm? - unit-testing

I was following Meteor's Angular testing guide and it told me to run unit test by using this command:
meteor test --driver-package practicalmeteor:mocha
I'm using WebStorm to edit my Meteor code, so I want to know is there any way to run/debug unit test in WebStorm?

Running tests
You have to make a Run/Debug Configuration in Webstorm for Meteor.
You'll have to set the program arguments correctly:
test --driver-package practicalmeteor:mocha
You run the tests by running this configuration.
Debugging tests client-side
You can use the previous configuration and debug using the browser's console.
Debugging tests server-side
Make a new Meteor configuration with arguments:
test --driver-package practicalmeteor:mocha --debug-port 5858.
Running this configuration you'll see an output similar to:
W20170409-20:19:21.287(2)? (STDERR) Debugger listening on [::]:5959
You can then debug the code by browsing to: http://localhost:8080/debug?port=5959
Note: in my case the port in the console differs from the port in the configuration. I have to use that port in the url.

Related

Debugging Unit tests with Atom (Vue application)

Is there a way to debug, via breakpoints, unit tests on a VueJS project?
I currently have the default Vue CLI setup and am using the official Vue plugin for Mocha-Webpack, as configured by the CLI. I am trying to figure out how to connect any of the debugger packages in Atom with the cli command that runs our unit tests.
The desired outcome is that I can add a breakpoint within Atom IDE and run 'vue-cli-service test:unit' and have it stop at each breakpoint so we can properly debug out unit tests. A nice to have would also be the ability to run individual tests as well with the ability to debug with breakpoints.
I have searched and have not been able to find anything. Out tests are running as expected but being able to debug them would be a huge help. Thanks!

Run grails functional test without having embedded tomcat start

I have a project that I am usually debugging/running using the grails run-app command. I would like to run a test but without having the server run again only for the specific test.
I usually run the server in debug mode all the time in the background.
I've tried playing around with the run configurations in iteli-j, with latest try being grails test-app functional: className
In Grails 2.4.4 if you override the baseUrl you can run your tests against a server other than localhost. For example, we have a pre-production server hosted on AWS and we run a subset of our functional tests against it from Jenkins, post-deploy, as a smoke test.
grails -plain-output test-app -baseUrl=https://foo.bar.org/ -echoOut -echoErr functional:
That works, but test-app still starts the embedded tomcat server. However, with a bit of digging, I found that overriding the server host to point to a running instance will cause the tests to run without starting the embedded tomcat. There are a couple of ways to accomplish this:
Pass the value on the command line:
grails -plain-output test-app -Dgrails.server.host=foo.bar.org -baseUrl=https://foo.bar.org/ -echoOut -echoErr functional:
Or, overriding the value in Config.groovy for the specific environment should also work:
...
preProd {
...
grails.server.host = 'foo.bar.org'
...
}
...
It isn't documented under test-app, but it is mentioned under run-app and it turns out it works for test-app too.
This works because Grails determines if the embedded server should be started by trying to open a connection to the server host/port, and if successful skips the startup.
From trial and error I have discovered that I have the best results when I specify both grails.server.host and -baseUrl even though the base url becomes redundant information. Possibly this is because my case involves an ssl connection, but I tried running with -https instead of -baseUrl=... and the tests just hung.
This plugin maybe helps you.
Grails functional-test-development Plugin
This plugin aims to make developing functional tests for Grails more convenient by facilitating running your tests against an already running application. It utilises the improved functional testing support added in Grails 1.3.5 and does not work with earlier versions.

Can I run my Ember CLI tests in the browser on my Jenkins CI server?

I'm trying to get my CI server to run my ember-cli test suite. By default, ember test runs the tests using PhantomJS.
Is it possible to have the command use qunit instead, pop open a browser, and return with the appropriate status code?

Unable to execute unit tests in a maven project from within intellij

I have inherited a legacy project with 100s of tests, and dependencies defined within the pom.
All of the tests run when I execute a mvn clean install from the command line, but when I try to execute one of these tests in debug mode from within Intellij i get the following error.
java.lang.NoClassDefFoundError: Could not initialize class
How can I get intellij to recognise these dependencies when trying to run a test in debug mode from the ide?
I managed to solve this by simply changing the working directory location in the Run configuration to point to the correct classpath location. The default location had been taken from a parent project.
It would be very convenient if one was able to debug tests from within IntelliJ. I have run into similar issues with my massive project and have found a workaround for it.
When wishing to debug a test, I have often found it useful to use a remote debugging session like so:
mvn -Dmaven.surefire.debug="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -Xnoagent -Djava.compiler=NONE" -Dtest=com.autofunk.TheFunkImplTest test -DfailIfNoTests=false
You can then attach to the above using a remote debug session from within IntelliJ on port 8000.
Therefore, when debugging tests I first check to see whether a simple debug from within Intellij works. If not, I run the above and then attach to it using a debug configuration like so:
IntelliJ execute unit tests without mvn command.
a IntelliJ plugin: MvnRunner
You can run tests using the maven project window in IntelliJ
View - Tool Windows - Maven Projects
Then under the project or module you wish to test open the lifecycle goals and click test.
This will run the currently configured test goal. Now the report is logged into the target directory
I use
https://github.com/destin/maven-test-support-plugin
to view the test results.
You can access this screen once the plugin is installed from the Project window again right click on the projects root and select "Show Test Results" (should be below the maven icon)
Good luck

Unit test results not showing in Sonar when building child projects in Jenkins

I have some maven projects configured in Jenkins, and I execute them from a parent project (which have them as <modules> in its pom.xml, the children have this project defined as <parent>).
The unit tests execute successfully for each project in Jenkins and it shows the results, but then in Sonar all projects appear as having no unit tests.
The sonar configuration for each project is
sonar.projectKey=project:key
sonar.projectName=project_name
sonar.projectVersion=1.0
sources=src/main/java
tests=src/test/java
binaries=target/classes
Do I have to do anything else in order for Sonar to pick up the results of the unit tests being executed?
Thanks in advance.
From what I see, I guess you're trying to run Sonar analyses with the Sonar Jenkins plugin "on-the-fly" mode, where you specify properties.
You have to understand that this mode does not support running tests: it can only reuse test reports (if you specify "sonar.dynamicAnalysis=reuseReports").
But as you are using Maven, why don't you just run the Sonar post-build action? (see documentation for that)