How to debug through a cucumber karate project - cucumber

I have inherited a Java / Maven / Cucumber project. I am fairly new to Cucumber.
Inside one of the folder I have a class like this...
import com.intuit.karate.junit4.Karate;
import org.junit.runner.RunWith;
#RunWith(Karate.class)
public class RoadsRunner {
}
Then in the same subdirectory / package I have a .feature file.
with a number of scenario's.
Feature: Check transaction
Background:
* url apiHost + '/api/v1'
* configure headers = {'X-TransactionID': '#(Math.random().toString())' }
Scenario: Get Classes
# get classes
Given path '/myUrl/classes'
And param processName = 'myProcess'
When method get
Then status 200
Question One.
I am using Eclipse. Is there a way I can debug through the test in a similar way that I would debug a Java app?
I have downloaded myself the Cucumber Eclipse plugin but can't quite figure out how to use it.
Question Two.
Without using a custom plugin to debug is there anything I can add to the scenarios to maybe print extra debug information.
thanks

The Cucumber Eclipse plugin gives you 2 things:
IDE syntax coloring / formatting support
Being able to right-click and run a Feature directly without the JUnit "runner"
Karate is Java behind the scenes so you can debug and set break-points, but it may not be as seamless as you expect. In 0.6.0 you have the option of placing a conditional break-point in Karate code that runs before / after each test step - see screen-shot.
So as you rightly called out, printing to the log might be the most effective way to work through complicated test scripts. Please refer to the print keyword - which is exactly what you are looking for.
2 more points:
the optional HTML report includes all HTTP request / response logs - which is great for troubleshooting a test.
I would love for the Karate UI (currently in alpha) to become stable sooner and be the best option for debugging, please do submit feedback and contribute if you can.
EDIT: we now have the Visual Studio Code IDE support with first-class debug support: https://github.com/intuit/karate/wiki/IDE-Support#vs-code-karate-plugin
EDIt2: If you want to debug Java code, that is possible with the new IntelliJ plugin: https://plugins.jetbrains.com/plugin/19232-karate

As per the documentation here, At this moment best way to debug Karate Steps is using Visual Studio Code for developing tests and VS Code Karate Plugin for debugging.
Visual Studio Code is Free, built on open Source and runs on all platforms including mac/linux and windows.
Please note this
The Karate UI has been retired and is not available in 0.9.5 onwards !
Use the VS Code Debug Support instead.
As per the comment by Peter Thomas, Eclipse/IntelliJ may also support debugging but I am unable to find any development there.

Related

How to Unit Test a C++/WinRT Component? Preferably with Code Coverage

I'm in the process of writing some new C++/WinRT based components in order to replace some much older C++/CX code. The goal is to be able to use third-party C++ tools that don't understand CX (static code analyzers, etc).
However the first step in the journey is to ensure I can properly unit test my own code. Unit testing C++/CX code typically used the "C++ Unit Test App" project type, which is C++/CX based and has its own issues (lack of code coverage support, run all required before tests show up in the explorer, stability, etc)
Browsing through the available project types in Visual Studio 2017, I did not see a unit test project template for C++/WinRT based projects. Is my only option to use the "C++ Unit Test App" template with all its failings, or is there another way to build tests for a C++/WinRT library?
Perhaps there is a way to configure either the "Native Unit Test Project" or "Google Test" project templates to support what I'm looking for?
Ideally what I'm looking for is something that doesn't require launching a UI, is pure C++(/WinRT), and supports Visual Studio's Code Coverage Analysis.
There is no unit test project that is specific to C++/WinRT, much like there isn't one for other libraries like STL. I would recommend Catch2 as it supports C++17 (a requirement for C++/WinRT) and works well on Windows. It is also what we use for testing C++/WinRT itself. Catch2 is nice because it helps you create a simple console app that acts as the test driver that includes all of the tests.
For code coverage I don't have a strong recommendation, but if you are using Visual Studio then you might want to try VSInstr. It can be used for code coverage and produces a report that can be viewed with Visual Studio.
Make sure your code is built using the /profile linker option. This will ensure that profile hooks are included in a dedicated section of the PE file. Next, run vsinstr to instrument any of the binaries you're interested in (that were previously built with /profile):
vsinstr /coverage tests.exe
Now run vsperfcmd to begin collecting coverage data:
vsperfcmd /start:coverage /output:report
Run the code as normal. For Catch2, you can simply run the executable at the command line. Then you need to stop the collection as follows:
vsperfcmd /shutdown
And you're done. You can now view the report in Visual Studio:
devenv report.coverage
Hope that helps. Again, this is not specific to C++/WinRT and since C++/WinRT is a header-only library you are liable to get a lot of noise that is unrelated to your specific project. I haven't found a good way to deal with that yet.
Expanding on my comment to #KennyKerr's answer for those that are interested...
If you are planning on using Catch2 as recommended, then the C++/WinRT Windows Console Application template is a great starting point. Pretty much all you have to do is tweak the main() to setup Catch2 and start writing your test cases. My only complaint is that the C++/WinRT templates don't allow you to add Windows Runtime Component project references via the UI (must be done by editing the vcxproj). There is probably a similar problem adding NuGet package references.
As noted in my comment above, there is a Catch2 test adapter for Visual Studio 2017/2019 in the marketplace. Be aware that it requires a .runsettings file to enable the adapter and to tell it which projects are Catch2 test applications (via a regex). Without a properly configured runsettings, it will not find your tests. I also had to increase the discovery timeout, otherwise it "forgot" my tests occasionally.
With regards the code coverage, when using Visual Studio you can configure the code coverage to include/exclude functions in the .runsettings file. See Microsoft's Site for details. For myself I added the following in the CodeCoverage section and it works pretty well so far:
<Functions>
<Include>
<Function>.*YourNamespaceHere.*</Function>
</Include>
<Exclude>
<Function>winrt.*GetRuntimeClassName</Function>
<Function>winrt::impl.*</Function>
<Function>winrt::(?!YourNamespaceHere).*</Function>
</Exclude>
</Functions>
For those that are trying to test a C++/WinRT Windows Runtime Component like me, and have code that is not exposed as part of the WRC interface, here is what I did to make that testable...
Create a C++ Shared Items Project
Move all of the code for your Windows Runtime Component (WRC) project into the shared items project, and out of the WRC project. Going forward, only add/remove files from the shared project. That way you don't have to touch the WRC or Test projects when files are added/removed.
Add a reference to this shared items project in both your original WRC project, and your test project
Make sure your test project and WRC project are configured similarly with respect compile settings and project/NuGet references
Edit the test project and ensure the RootNamespace is configured the same as the WRC project (probably has to be done via your favorite editor). This is required otherwise the generated headers will be prefixed with the namespace, and thus won't be found by the shared code.
(Optional for Code Coverage) In the test project, enable profiling (Linker > Advanced > Profile > Yes)
You should now be able to write tests that exercise the private code. As to whether or not this is the best approach, I leave to the reader. It works for me, and the code I'm testing is simple enough that I'm not overly concerned with the project definitions not aligning perfectly. Your mileage may vary.
I will note that the above can also be used to make the "Native Unit Test Project" work with C++/WinRT, you just have the extra steps of integrating the C++/WinRT bits into the test project first.

CodeNarc Maven Plugin

We have a project that uses Groovy extensively and we use Maven to build our artifacts. (IntelliJ as our IDE)
We wanted to incorporate some automated code-style checking, and thought we might use codecarc-maven-plugin. However, since that was from Codehaus, which gone now, is the plugin actively supported somewhere else?
Any other good options to run a Groovy style checker automatically during a Maven build?
That's a good catch. I'll add a pull request to update the website link. You can find the new plugin information on GitHub: https://github.com/gleclaire/codenarc-maven-plugin

Visual Studio 2015: Bug setting TestFramework to Mocha for unit test files in NodeJS Project

I'm working on a Typescript project in Visual Studio (2015 Community edition) build server side unit tests using Mocha.
I however read that NodeJS Tools supports running within the VS Test Runner, and even Typescript unit tests. You have to set the TestFramework property of the file to 'Mocha'. The project I'm working on even already has existing tests which this is set for. However I don't get a dropdown option in the GUI to set it, it's just empty:
I'm using NTVS v1.1 (and Typescript 1.7). Am I missing something in my Visual Studio setup? The build type of the test .ts file is also already set to TypeScriptCompile. Perhaps more of a specific VS question than a programming question, but the environment/tools is so programmer's specific that I thought somebody here can help me.
PS Running tests manually each time is driving me crazy, and I bumped into too many problems with using a HTML spec runner which I tried first, because this server side tests (e.g. CommonJS require and import statements that my browser doesn't get) and also because it's TypeScript.
But alternative solutions are also welcome. I'm using grunt and am also experience using Gulp, I'm just hoping for a full solution, not something that'll cost me half a day to script together, debug and document..
Note: I DO get the dropdown to select Mocha Testframework for .js files (after including in VS project), but NOT for .ts files :S.
Hmm... pretty silly, but it seems indeed a GUI issue:
You simply have to type Mocha into the property field yourself manually.
In the case of Typescript there doesn't appear a dropdown (e.g. caret) on hoover in the 'TestFramework' field. My expectation was really fixed on the dropdown' experience beause it DOES do that for Javascript files and in so many other fields in the 'Properties' window.
So a short overview of things to do:
type yourself and make sure you don't type Mohca or something:).
Install Mocha locally
Make sure the BuildAction of the .ts file is set to TypeScriptCompile
I'm off fixing other issues, this Typescript is nice, but the tools and language are evolving too fast for the 'Google-based development' I have to rely too really work well :S.

Spring-boot-devtools not restarted when change groovy-files

In my project I work with spring-boot and groovy. Also I using spring-boot-devtool. This is a good tool that helps me.
But, when I change groovy-files, server not restarted, I have to change other files
Like a IDE I use a IDEA. The project assembled and tested with the command
gradle bootRun
Has anyone experienced this and found a solution?
In my case pattern !?*.groovy was absent in Resource patterns in Compiler settings
Try with <CTRL+F9>
I am using Spring Boot 1.3.0-RELEASE with groovy only.
Maybe this auto-generated demo project may help you to compare what went wrong with your project, using Sring CLI (installed via SDKMAN):
run in command line: spring init --dependencies=devtools,web --type=gradle-project --language=groovy example
Import to IDEA
run gradle bootRun
change source and hit <CTRL+F9>

Running sample projects in MvvmCross v3 (Hot Tuna)

I'm trying to run sample projects (viz. BestSellers and Conference) that are present in MvvmCross v3 branch. I resolved the strong assembly reference issues successfully. However each time I run a sample project, I get System.TypeLoadException in MvxFullBinding and MvxValueConverterRegistryFiller classes.
Exception in MvxFullBinding class:
Exception in MvxValueConverterRegistryFiller class:
Is anybody able to run the sample projects successfully? How do I get around these exceptions?
It looks like you're running this as the 'Touch' projects from Visual Studio? In which case you are way ahead of what I've managed to achieve.
If that is correct, then I suspect that what you are seeing is that you have:
built proper PCLs built in VS/Windows against the portable reference assemblies
but these cannot be executed against the current MonoTouch/Xamarin.iOS runtime.
If you try, you may see issues like: iOS black screen and MissingMethodException: Method not found: 'System.Type.op_Equality'
For some more info see 'almost portable binaries' on http://slodge.blogspot.co.uk/2013/01/almost-portable-binaries.html
There is 'proper' PCL support currently being worked on within XamLabs - so I am hopeful that there may be a solution to this problem arriving in the Xamarin.Android Alpha channel any day now - but don't expect this to be painless initially.
Of course, I might be wrong on this - this really is new territory and I will be fascinated to hear/read about your adventures. If you want to try to find more detail, then it may help to try looking deeper into the exception details, and looking into the console log trace on your mac.
For these two particular exceptions, I can confirm that both samples...
... although that is when I'm working on my Mac.

Resources