Test results for skipped tests - cucumber and webdriver io - cucumber

I am using allure to generate my test report and I noticed I had no "skipped" tests being reported - I knew I had some skipped tests. Digging through the code, the skipped tests are not being run (which is correct) but there is no result being generated. I was sure that using mocha I would still get a result file for skipped tests.
I am using the latest (as of now) webdriverio plugin as well as cucumber 7.0.0
Does anyone know if there is a way to "force" a result to be created for a skipped test?

Related

Jest test coverage gives 100% coverage for modules that have no tests at all

I'm experiencing 2 issues with Jest test coverage:
1- Jest reports 100% (Stmts, Branch, Func, and Lines) coverage for modules with no tests at all but required by tested modules
2- Jest reports 100% Branch coverage for modules with no tests nor required by tested modules
In the image:
sum is a tested module
toNum is not tested but required by sum
sub is neither tested nor required by tested modules
I've create a repo that reproduces the issue:
https://github.com/hossamnasser938/Reproduce-Jest-Coverage-Issue
Here is my package.json:
Here is my folder structure:
How do I remove the entry for sub.js from the coverage report? I really appreciate your help.
1- Jest reports 100% (Stmts, Branch, Func, and Lines) coverage for modules with no tests at all but required by tested modules
This is expected behavior when you configure Jest to collect coverage. The required modules are still executed by your test, despite them not having a test of their own. The documentation for collectCoverage states
this retrofits all executed files with coverage collection statements
Your test is executing all of the code from the required module, so the module is covered completely, 100% by your test code. Even though the module is executed by another test, you should still write a separate test for the required module to ensure it works in isolation as a unit.
2- Jest reports 100% Branch coverage for modules with no tests nor required by tested modules
Again this is expected behavior given your configuration value for collectCoverageFrom which includes sub.js, and your implementation of sub which has no branching, so Branch statements would be 100% executed (because there are none).
If you want Jest to stop reporting on sub.js then you have a couple of options:
Remove the configuration for collectCoverageFrom entirely, and
that will remove the entry for sub.js from the coverage report
table.
Modify your value for collectCoverageFrom to specifically
ignore sub.js:
collectCoverageFrom: ['src/**/*.js', '!src/**/sub.js']
Personally, I would leave everything as-is to serve as a reminder that sub.js still needs to be tested with adequate coverage.

Does the Jest --changedSince option also test related files?

I've tried to look at the source code but I am a little confused. Does the Jest changedSince option also test related files?
Yes, to be more specific it's doing an inverse resolve of dependents.
When it comes to actually reporting coverage, it will run tests as mentioned, but it will only report the coverage of the changed file(s).

How to run only the tests defined in feature files with nightwatch-cucumber

If in my package.json I define a yarn script test that only calls nightwatch command; It seems as it is that it'll run both the scenarios that are found in the features folder as well as any test that is not necessarily a test made with Cucumber (plain nightwatch tests under the tests/ folder).
Is there a way for me to distinguish the execution of only the "cucumber+nightwatch" tests from the plain nightwatch ones, so I filter and only run from one of the two sets?
The author of nightwatch-cucumber suggested this approach via e-mail:
use an environment variable in nightwatch configuration (JS based).
This environment variable can decide the source of the tests.
One note: this package will be deprecated if nightwatch 1.x will come
out. So I suggest not to invest to much time with it instead use the
new nightwatch-api package.
A quick workaround to filter out plain nightwatch tests from the cucumber+nightwatch ones was to edit the src_folders in the nightwatch.json file to an empty array, like this:
{
"src_folders" : [],
...
}

maven Cobertura reports not working as expected

I am using maven with cobertura plugin for my application. The test class what I have written is for controller and running fine without any issues in eclipse.There are so many dependencies on other classes.I am using mockito and powermockito both .
When I run
mvn clean test
from command prompt it shows all the test cases that are passed.I have around 9 test cases, but when I run
mvn cobertura:cobertura
it shows only one test case run
Tests run: 1, Failures: 0, Errors: 1
The error what it is showing is in different class[assume it as X class] which I have not modified but I am mocking this X class in my test class.
1)
Does cobertura depends on other classes also apart from main test
class for code coverage? If so what I need to do .
2)
I am not using injectmocks in my test class instead I am using new
operator to call the controller class.Since inject mocks was calling real methods I have not used this.
Any help would be appreciated

How to get code coverage information using Node, Mocha

I've recently started getting into unit testing for my Node projects with the help of Mocha. Things are going great so far and I've found that my code has improved significantly now that I'm thinking about all the angles to cover in my tests.
Now, I'd like to share my experience with the rest of my team and get them going with their own tests. Part of the information I'd like to share is how much of my code is actually covered.
Below is a sample of my application structure which I've separated into different components, or modules. In order to promote reuse I'm trying to keep all dependencies to a minimum and isolated to the component folder. This includes keeping tests isolated as well instead of the default test/ folder in the project root.
| app/
| - component/
| -- index.js
| -- test/
| ---- index.js
Currently my package.json looks like this. I'm toying around with Istanbul, but I'm in no way tied to it. I have also tried using Blanket with similar levels of success.
{
"scripts": {
"test": "clear && mocha app/ app/**/test/*.js",
"test-cov": "clear && istanbul cover npm test"
}
If I run my test-cov command as it is, I get the following error from Istanbul (which is not helpful):
No coverage information was collected, exit without writing coverage information
So my question would be this: Given my current application structure and environment, how can I correctly report on my code coverage using Istanbul (or another tool)?
TL;DR
How can I report on my code coverage using Node, Mocha, and my current application structure?
EDIT
To be clear, Mocha is running tests correctly in this current state. Getting the code coverage report is what I'm struggling with getting to work.
EDIT 2
I received a notification that another question may have answered my question already. It only suggested installing Istanbul and running the cover command, which I have done already. Another suggestion recommends running the test commands with _mocha, which from some research I have done is to prevent Istanbul from swallowing the flags meant for Mocha and is not necessary in newer versions of Mocha.
You should try running your test like this :
istanbul cover _mocha test/**/*.js
You need an .istanbul.yml file. I don't see any reference to it - hard to say without knowing the contents of it.
I don't think there's quite enough information to solve this in the question. I'll update this answer if you update the question, especially before the bounty expires, eh?
This is how i get code coverage on all my js projects (looks like the one from Sachacr) :
istanbul cover _mocha -- -R spec --recursive test

Resources