How to add breakpoints to .feature files - debugging

As a developer
I want to put breakpoint(s) in feature files
So that I can debug a feature/scenario/step
Have any of you implemented this functionality with Behave or Cucumber?

You can not put breakpoints to .feature files, because it is a plain text files. Instead you can put breakpoints inside test-steps which implement your BDD steps.
Example
When I click button "save"
Then saved page opened
You need to go inside that step and see something like that:
public void iClickButton(String buttonName) {
getButtonByName(buttonName).click();
}
You can put breakpoint inside method iClickButton and debug it.
That is how you can debug execution in BDD style.

I can't say I've ever been able to put breakpoints in feature files. Instead, I put them inside the step files so when that step runs, you can verify it did its job. It's a lot of switching back and forth between feature and step files, but it works

I just want to point out that in 2018 feature files are used by a lot more than Behave or Cucumber [i.e. Codeception for PHP]. "Gherkin" is supposed to be a business readable DSL and the concept of a "breakpoint" really doesn't apply in that domain. I'd say it's definitionally impossible to put a break point in a Gherkin feature file. You could certainly do that if you want, go for it, but there isn't a standard way of doing it, and it's possible you'd be confusing things in a large organization or team.

First of all you need to add debug in step definition not in feature file
Now, You are running it by maven command like:
mvn clean install
But you need to run it using junit or testng.
Put an debug point in your step defination and run the project as junit/testng in debug section
OR
If you still need to run it using maven you can try below parameter in maven command
-Dmaven.surefire.debug test -DforkCount=0 test

Related

Go language: Change the build folder when running "go run"

Using Go on Windows, whenever I execute go run myprog.go from the console, Go builds a new executable with a random name somewhere on my C drive.
Is there a way to configure it so it will always build the file to a specific location, and preferably to also avoid the randomness of the name? (i.e., always build to D:\Temp\LastBuild.exe).
I was able to find some info that did not help when doing go help run and go help build. The latter had an output flag -o outfile but it is not accepted in go run.
Any help is appreciated.
Do not use go run. It's intended for quick testing out snippets of code the size of a single screenful of lines.
The working approach is
Edit the code.
go build it.
Run your executable which will have predictable name.
Go to step (1).
If you write tests in parallel with the implementation (and you should), this changes to
Edit the code.
Edit the test suite.
go test it.
Go to step (1).
Please see this recent thread on the mailing list for more insight on the same subject.

Is there option to run some .exe when starting MSTest tests?

I'm writing tests using MSTest. I need to run executable from another project (in solution) before tests starts.
Is there other option beside invoking exe directly under [ClassInitialize]? In this case I'm loosing debugging capabilities.
Something like Multiple startup projects in solution properties.
If it is in the same solution, can't you add a reference to it in your test project and call it directly from [ClassInitialize]. This shouldn't cause you to lose debugging capabilities. Do you not have access to the source code of the executable?

Running JSCoverage with Jasmine

A little new to Javascript coding, so please bear with me.
I read through the following link
jasmine with jscoverage automated testing
However, since I don't have a Ruby project, it didn't seem to be what I wanted.
Here are the steps I executed:
Copy my js file to be tested to a directory 'input'
Run the following command 'jscoverage input output'
Copy my spec and src folders for Jasmine as well as SpecRunner.html into 'output'
Copy the instrumented source file into src
Open jscoverage.html in Chrome
Open SpecRunner.html in the 'Browser' tab
At this point, the browser page displays my Jasmine tests. However, the 'Summary' page shows 0 files tested and the 'Source' tab is grayed out.
I know I messed up somewhere but am not sure where. Please help me out. Thanks!
The correct steps to be followed are as follows:
Copy the jasmine files (spec and src folders for Jasmine as well as SpecRunner.html) to a directory 'input'
Run the following command 'jscoverage input output'
Open jscoverage.html in Firefox (Chrome will not show the individual files that were tested)
Open SpecRunner.html in the 'Browser' tab
This approach has the drawback that all the files including jasmine related js show up. But you can select your js file that's being tested and just look at the code coverage for it.
The standard jscoverage approach is to instrument the entire codebase you want to get coverage on, then run a suite a tests and generate a report. This approach is a bit heavy handed since a codebase only needs a coverage report on a set frequency. Unlike CI tests, how often does the dev really need to know the coverage percentage change, weekly?
The node.js jscoverage project uses the same 'instrumentation' approach as the larger jscoverage project, but it can be run from the node CLI on an individual file, or from code on one or more files, as they are called from the tests themselves. In place of separate step to 'instrument' a batch of files, the jscoverage (confusing name), 'instruments' at test runtime.
I have been working towards a pattern that allows jasmine tests and testing in either a browser or at the CLI using the same source code setup and test configuration. Still beta. The jasmine just-in-time 'instrumentation' is not done yet.
https://github.com/d1b1/jasmine-jscoverage

Is there a way to "Test" current file in Xcode4?

Is there a way to "Test" current file in Xcode4?
That is if you are writting your 10th unit test, but rather than going TEST and having all unit tests run, you want to only trigger running those testing in the unit test file you are current in?
Pretty old post, but Xcode evolved since.
In Xcode6, got to Product > Perform Action
You'll see some other Test options, like Testing the current function.
The shortcut is Cmd-alt-ctrl-U. Pretty difficult with a single hand if you're not a pianist.
It looks like Xcode 4 is heading that way, but it doesn't work well:
Edit scheme
Go to Test section
Expand to show checkboxes.
Unfortunately, you have to click individual checkboxes; there is no way to select the entire group, or even individual suites, and turn them off with a single click. Ideally, it would be nice to turn off everything, then reenable only the tests you want.
As a workaround, you can set up a test target containing the infrastructure to run any test, but not containing any tests. Call it something like "Ad-hoc Tests". Then take the test suite you want and temporarily add it to the target. Use the technique described above to turn off all tests in your main test target.

How do I run (unit) tests in different folders/projects separately in Visual Studio?

I need some advice as to how I easily can separate test runs for unit tests and integration test in Visual Studio. Often, or always, I structure the solution as presented in the above picture: separate projects for unit tests and integration tests. The unit tests is run very frequently while the integration tests naturally is run when the context is correctly aligned.
My goal is to somehow be able configure which tests (or test folders) to run when I use a keyboard shortcut. The tests should preferably be run by a graphical test runner (ReSharpers). So for example
Alt+1 runs the tests in project BLL.Test,
Alt+2 runs the tests in project DAL.Tests,
Alt+3 runs them both (i.e. all the tests in the [Tests] folder, and
Alt+4 runs the tests in folder [Tests.Integration].
TestDriven.net have an option of running just the test in the selected folder or project by right-clicking it and select Run Test(s). Being able to do this, but via a keyboard command and with a graphical test runner would be awesome.
Currently I use VS2008, ReSharper 4 and nUnit. But advice for a setup in the general is of course also appreciated.
I actually found kind of a solution for this on my own by using keyboard command bound to a macro. The macro was recorded from the menu Tools>Macros>Record TemporaryMacro. While recording I selected my [Tests] folder and ran ReSharpers UnitTest.ContextRun. This resulted in the following macro,
Sub TemporaryMacro()
DTE.Windows.Item(Constants.vsWindowKindSolutionExplorer).Activate
DTE.ActiveWindow.Object.GetItem("TestUnitTest\Tests").Select(vsUISelectionType.vsUISelectionTypeSelect)
DTE.ExecuteCommand("ReSharper.UnitTest_ContextRun")
End Sub
which was then bound to it's own keyboard command in Tools>Options>Environment>Keyboard.
However, what would be even more awesome is a more general solution where I can configure exactly which projects/folders/classes to run and when. For example by the means of an xml file. This could then easily be checked in to version control and distributed to everyone who works with the project.
This is a bit of fiddly solution, but you could configure some external tools for each of group of tests you want to run. I'm not sure if you'll be able to launch the ReSharper test runner this way, but you can run the console version of nunit. Once you have of those tools setup, you can assigned keyboard shortcuts to the commands "Tools.ExternalCommand1", "Tools.ExternalCommand2", etc.
This wont really scale very well, and it's awkward to change - but it will give you keyboard shortcuts for running your tests. It does feel like there should be a much simpler way of doing this.
You can use a VS macro to parse the XML file and then call nunit.exe with the /fixture command line argument to specify which classes to run or generate a selection save file and run nunit using that.
I have never used this but maybe it could help....
http://www.codeplex.com/VS2008UnitTestGUI
"Project Description
This project is about running all unit test inside multiple .NET Unit tests assembly coded with Visual Studio 2008."

Resources