Where does CucumberTestCase belong? - cucumber

I'm trying to follow Android BDD with Cucumber and Espresso — the full guide but I'm getting the error:
"No tests found."
I can see in the logs that the CucumberTestRunner got invoked successfully. So it seems like Cucumber can't find its own test cases. I think my .feature files are in the right place, so that only leaves CucumberTestCase which could be misplaced. The tutorial puts it in a packaged called com.sniper.bdd.test.
Where does CucumberTestCase belong?

I was able to get Cucumber to find the tests by putting CucumberTestCase in the package <package name from AndroidManifest>.test.
So in the tutorial I guess it should have been in com.sniper.test not com.sniper.bdd.test.

Related

how to run Groovy script in Netbeans?

I'm trying out NetBeans for editing Groovy code. (I'm new to Groovy, and it's been a long time since I did any Java development).
At some point I installed the Groovy plugin via the "plugins" tool. But it does not have the green checkmark under "active", and choosing the Groovy plugin does not make the Activate/Deactivate/Uninstall buttons available. Oh well...
So let's create a project...
Choose "new project". I'm choosing "Java with Maven" just because it's the first one.
Hit "Finish"...and voila, I have a project.
Let's create a file...
Right click the project package in the left pane, choose "new"
Choose "Groovy Script" for a type, hit "finish"
Hey, I have a very simple script. Looks like it should say "Hello chris!" when done.
Hit the "play" button on the toolbar....things appear in the output window.
But wait a minute...the output is "Hello World!", and it should be "Hello chris!" It looks like "HelloWorld" is coming out of "Mavenproject1.java".
How can I (or can I) just run my script from within NetBeans?
UPDATE: per #andrewJames suggestion, I tried working that tutorial. (It looks like the tutorial may be a bit out of date.)
I created a "Java Ant" project, as that was the only one that offered me the option of not creating a "Main Class File".
I created the Java form, and the Groovy class, as directed.
When I run the project, I get an error message saying "Error running forked groovyc".
I get that same error whether I'm running on a machine with a groovyc executable or not, so I suspect that there's something about the configuration that I need to change in order to point to the groovyc executable.
Probably something to do with the build.xml file...but I can't seem to figure out how to edit that to change the search path for the groovyc step.
I had the same problem that NB doesn't run a Groovy script out of the IDE like Eclipse does. I logged an issue and spent more than a year on the netbeans-dev mailing list advocating for it. Often replied to with "we'll be happy to review your pull request" type of stuff. Eventually, when I rage quit the mailing list with a scathing message, Geertjan replied to the issue with a solution.
So, in short, use the old plugin to create a Groovy project and change line 26 in groovy-build.xml to
<groovyc srcdir="#{srcdir}" sourcepath="#{sourcepath}" destdir="#{destdir}" encoding="${source.encoding}" excludes="#{excludes}" includeAntRuntime="true" fork="false">
You can then run your script with Shift+F6.
The project needs the Groovy jars added. It works for me on NB 11, 12 & 13 with Groovy 2.x and Java 8, 11 & 14 so far. I haven't tried it with Groovy 3.x as the groovy-all.jar is deprecated so you'll have to maven or manually manage the Groovy jars.
Also, I collaborated a bit with someone on a new plugin. It works as is but new development has stalled.

Puppet Development Kit test unit with multiple output targets

We have introduced the PDK lately into our developments chain and are now trying to make everybody happy with the test outputs it generates.
We need an output as JUnit test report for our jenkins jobs. That we have solved.
And we need the output still on the console because some of the developers find it very annoying having to open the JUnit report file before they can see failed tests.
pdk test unit --format=junit:report.xml
Is how we configured the output for JUnit.
Unfortunately as soon as you configure the JUnit report no output gets printed on the console/stdout anymore. Even if you add another format like --format=text without target file.
Is there a way to achieve both without running the PDK twice?
It doesn't appear to be in the docs, but this should work.
pdk test unit --format=junit:report.xml --format=text:stdout
See https://github.com/puppetlabs/pdk/blob/7b2950bc5fb2e88ead7321c82414459540949eb1/lib/pdk/cli/util/option_normalizer.rb#L10-L24
I've filed a ticket to ensure that gets promoted to the docs at https://puppet.com/docs/pdk/1.x/pdk_reference.html#pdk-test-unit-command
From PDK documentation
--format=[:]
Specifies the format of the output. Optionally, you can specify a target file
for the given output format,
such as --format=junit:report.xml . Multiple --format options can be
specified as long as they all have distinct output targets
So I believe ,you can try as below
pdk test unit --tests=testcase_name --format=junit:report.xml --format=text:log.txt
Hope it helps.

Fail code coverage if no tests exist for code

I have a simple Node JS application and am using Istanbul with Mocha to generate code coverage reports. This is working fine.
If I write a new function, but do not create any tests for it (or even create a test file) is it possible to check for this?
My ultimate goal is for any code which has no tests at all to be picked up by our continuous integration process and for it to fail that build.
Is this possible?
One way you could achieve this is by using code coverage.
"check-coverage": "istanbul check-coverage --root coverage --lines 98 --functions 98 --statements 98 --branches 98"
Just add this in your package.json file, change the threshold if needed. If code is written but no test then the coverage will go down.
I'm not sure if this is the correct way to solve the problem but by running the cover command first and adding the parameter --include-all-sources this then reported on any code without a test file and added them to the coverage.json file it generated.
Then running the check-coverage would fail which is what I'm after. In my CI process I would run cover first, then check-coverage
Personally I find the documentation on Istanbul a little bit confusing/un-clear which is why I didn't see this at first!

Not complete test suite with Spec Explorer 2010

I’m trying out Spec Explorer, and now I have this bug that my test suite is incomplete. I don't get an error or anything, it’s just that I would expect 16 test cases and I only have 11 of them.
The problem I have is with the sample project that is in Spec Explorer 2010. Because I’m new at this I was trying different stuff out with the sample project, so stuff like expanding the range and expanding the double add to quadruple add. This last one was where I noticed that I was missing some test cases. I changed it back to triple add, to watch if the problem was there to. And as I expected I missed a test case again. Only with the triple I expected 8 test cases and I only got 7.
The only thing I changed in the code:
machine DoubleAddScenario() : Main where ForExploration = true
{
(Add(_); Add; Add; ReadAndReset)*
}
I’ve also tried to do this
(Add(_); Add(_); Add(_); ReadAndReset)*
But same problem there. The test case I’m missing is the Add(1); Add(2); Add(1). I’ve also tried calling only this one, and that works, so why am I missing it in my test suite?
Am I doing something wrong, or does Spec Explorer filter something for me? And if it is Spec Explorer where does it make this decision?
good question. The reason why the test case is missing is, that Spec Explorer uses step (transition) coverage and not full path coverage as coverage criterion. So you will find a test case which uses in first step "Add(1)" another one which uses in the second step "Add(2)" and finally a test case which uses "Add(1)" in step 3 but not necessarily one single test case with the exact combination. You find the answers (as really a lot of question were asked there) in the forum and help of Spec Explorer:
http://msdn.microsoft.com/en-us/library/ee620427.aspx
http://social.msdn.microsoft.com/Forums/en-US/977b90c1-8938-474a-840e-14fd78b1af3e/spec-explorer-wmethod?forum=specexplorer
Spec Explorer is used in real world testing so the problem (only one of the many in MBT) with exponential explosion for path coverage had to be worked around. The extremely cool solution of Spec Explorer is the Cord-language (or regular language if you want). Instead of tedious programming test cases Spec Explorer allows us now to only sketch the test case with scenarios. The details and combinations comes out of the generic model. In practice this is what we (at least all the projects I did) really want. And as you see you can add your missing test case if you really need it.

Rubymine is not able to find a step definition, located inside a gem

Rubymine returns an alert of "Undefined step reference" for the two steps of this scenario. This cucumber test is like this:
#smoke
Scenario: Update profile Smoke test.
Given I navigate to this test webpage
And In Test, I click the element of "test_link"
This 2 steps are located inside a gem, following this structure:
gemname/lib/features/step_definitions/web_shared_steps.rb
And (/^I navigate to this (.*?)$/) do |web|
web = '$' + web.downcase.gsub(' ', '_')
#browser.goto eval(web)
end
Then (/In (.*?), I click the element of "(.*?)"$/) do |page, element|
on_page(page + 'Page').click_element(element)
end
And the methods are also in the gem, following this structure:
gemname/lib/basic_methods.rb
module BasicMethods
include PageObject
include PageObject::PageFactory
def click_element (element)
element = element.downcase.gsub(' ', '_')
wait_until{send("#{element}?")}
select = send("#{element}_element")
wait_until{select.visible?}
select.click
end
So, If I execute with the command line "bundle exec cucumber", the test is able to find the step definitions in the gem, and the methods in the gem, and everything is executed correctly.
But, Rubymine is still giving an alert of "Undefined Step reference" for the two steps of the scenario, and I am unable to "command click" in those steps in order to navigate to the step definition.
QUESTION: Since the test in working, how is possible to "tell" Rubymine the folder/location where it has to search for the step definitions?
I don't have Rubymine so I can't verify this answer but it sounds very similar to a problem I had with Syntastic under Vim.
Try creating a file called features/support/external.rb containing:
require "lib/features/step_definitions/web_shared_steps.rb"
Actually it doesn't have to be called external.rb, it can be called anything except env.rb.
I'm guessing that Rubymine is calling cucumber with the --dry-run option to generate its warnings. See this answer for details.
try putting the gem source on your machine and then add this to your gemfile
gem 'gem', :path => 'path/to/gem-source'
I've had a similar problem with trying to use my own fork of a gem
When i did gem 'my-gem', :git => 'my-repo.git' i had the same problem as you, but by using :path I got rubyMine to recognise my step definitions.
I need to switch back to :git in production but at least i have a solution for my dev environment

Resources