debug stepping java code when running cucumber feature file in Eclipse - eclipse

What I do:
Set up fresh Cucumber maven project using "cucumber-archetype" from io.cucumber in Eclipse 2022-09
Set break points in StepDefinition java source
Run "Debug as Cucumber Feature" on feature file open in editor**
Stepfilters disabled to make sure I'm not filtering anything out
What happens:
"Step into" moves ahead as with normal debugging, but does not go into any source to show line by line which java code is executing.
Expected:
"Step into" to go into source files to show line by line which code is executing, just as happens doing any other debugging with junit5 tests.
What I have tried:
Converting to Cucumber nature
Did maven update project
Project content
A test project contains these test scope dependencies, beyond imports cucumber-bom and junit-bom:
cucumber-java 7
cucumber-junit-platform-engine 7
junit-platform-suite 1.9.1
junit-jupiter 5.9.1
…so nothing more complicated than a base project is needed to get this behavior.
My questions:
Are my expectations of step debugging here unreasonable?
Have I perhaps missed some vital set up step for a cucumber project in Eclipse? Please note I have basically described above what set up I've done as this is an archetype.
If not, how could I set it up to allow stepping into code also when running a Cucumber feature file in debug mode?
** This is the only way to execute the feature file in Eclipse that I know of.

Here's one solution: Run the Cucumber runner java source file as a JUnit test in debug mode, instead of the feature file directly:
Right click on the Cucumber runner java source file
Select "Debug as" > "Junit Test" in the popup menu
This method both gets the input data as well as evaluation results from the Cucumber feature file and renders test results in the JUnit view as well (albeit not 100% useful). Most importantly code stepping into source now works as expected.

Related

Xtend import error in Junit test case

I am attempting to write a test case in Xtend using Junit 5 on Eclipse Oxygen. A screenshot of the Eclipse Java perspective shows the source code and the environment:
Here is a screenshot for the build properties for the project:
I am using Maven in this project as well.
Can anyone suggest what I need to doto be able to compile and run my test case?
I know this is an old question, but just I had the same issue so I'm posting this answer in case it's useful for anybody.
In the properties window, select Java Build Path (your second screenshot), then click on the tab "Source".
For the generated test sources, for example xtend-gen folders, toggle the option "Contains test sources" to be true. Then, set the option "Output folder" with the value target/test-classes.
When you apply the changes you your build should go back to normal.

How can I get Eclipse to re-compile my JUnit test when I make a change to it?

I'm using Eclipse Juno on Mac 10.7.5, Java 6, Junit 4.8.1, and Maven 3.0.3. I have imported a Maven project into Eclipse but am having trouble getting JUnit test compilations to refresh. When I edit a JUnit test in the editor, save it, right click on the test and select "Run As" -> "JUnit Test," Eclipse doesn't appear to be recompiling the test, rather using the original class file in my target/test-classes directory. When I compile on the command line using "mvn clean test-compile," the updated class appears correctly in the target/test-classes directory.
So my question is, how can I get Eclipse to properly compile my test and place it in the target/test-classes directory? I have verified in my project settings that under "Source," I have myproject/src/test/java with the output folder as myproject/target/test-classes with Included (All) and excluded (None).
Dave
This is strange. JUnit tests are treated just like any other Java file and they should be recompiled on save. First, make sure that Project -> Build automatically is enabled.
If yes, then go to the file system, delete the class file for your test and then make a whitespace change to the file from inside the IDE. Is the file regenerated? My guess is that it is.
If not, then take a look at your error log and paste any relevant errors here.

Compiling in Eclipse/STS produces no output

I'm a Visual Studio .NET developer who's trying to switch to Eclipse/SpringSource Tool Suite, so I get stuck on probably simple problems. Please bear with me.
I'm working on a Spring MVC project associated with an Apache Tomcat server. If I right-click the server and choose Start (alternatively Package Explorer->right-click project->Run As->Run on Server), my project is compiled and started. Compiler output is shown in Console window. Fine.
But if I simply want to compile the project without running it, I try selecting Project->Build All, Project->Build Project, or Project->Build Working Set. Nothing happens, no screen output, nothing -- despite having non-compiling code.
I expected to see the compiler errors on screen, preferably with the errors highlighted in the code. For what it's worth, I have deselected Project->Build Automatically. Anybody knows what I should do?
Eclipse and STS use incremental compilation. So, every time a file is saved, it is automatically compiled (as well as all files dependent on it). When you deselect Build Automatically, then yes, you will need to explicitly build, but this will still be an incremental build (ie- only the changed files and dependencies).
See here for a bit of a discussion on how incremental building works in Eclipse: http://www.eclipse.org/articles/Article-Builders/builders.html

Unable to run a Subclipsed Groovy script in Eclipse

After installing the Groovy plug-in in Eclipse, clicking Run brought up a list: Groovy Console - Groovy Script - Java Application. I'd select Groovy Script and it would take off.
Now, after checking out a colleague's Groovy project with Subclipse, opening a script in it, clicking Run brings up "The selection cannot be launched, and there are no recent launches".
Selecting Run As... shows '(none applicable)'. So I select Run Configurations... and click Groovy Script, but the Run button stays dimmed. Eclipse evidently needs more info, but what?
I suspect your colleague didn't check in the .project file. It contains the "nature" that defines the project as being a Groovy project. I don't know for certain but it is not uncommon for eclipse actions to be predicated on the presence of an appropriate nature.
I would also check the .classpath is present and valid as it should contain the Groovy libraries required to compile and run your script.
Assuming they are missing, get your colleague to add them, and after syncing you should be good to go.

Eclipse: bind some key for all unit tests

I practice TDD and run my tests very often. Eclipse has a nice command to run the last-launched configuration. But when I invoke the command in some unit test class, Eclipse runs only the tests for current unit test class. I want run all my unit tests instead.
Yes, I can use the mouse to invoke the command that runs all JUnit tests, but, to repeat: I run tests very often.
You need to change eclipse's run mode. By default, it will try to run whatever is selected or being edited. You want to it always run the "last thing executed".
Go to Window->Preferences->Run/Debug->Launching
Choose "Always Launch the Previous Application"
Then you can define a TestSuite with all of your test cases and run it, or run all test cases for the project. Once run, you can just keep re-running with F11 or control-F11.
Hope this helps!
-- Scott
Maybe Infinitest is what you need.
You can create a JUnit launch configuration for all of your tests by right clicking the tests folder and choosing "Run As > JUnit Test".
Then see https://stackoverflow.com/a/8176077/255961 which describes how to use the Practically Macro plugin to assign shortcuts to launch configurations.
PS, If for some reason you have tests in more than one folder you can then edit the JUnit launch configuration to work at the project level as well:
To run all unit tests in a project, package or source root, select the item in the package explorer and hit Shift+Alt+X then T (or right click->Run As-> JUnit test).
To get the focus on the package explorer, hit Ctrl+F7 to bring up the "Next View" menu, hit it repeatedly to cycle through the list or hit up and down arrow then enter to select the view.
Once you've run it once, F11 can be set to run the last launched if you tweak the debug preferences (the default is to run for the current selection).
There is also Junit Max. It is not free but very cheap. It will run all your tests every time you save a file and indicate if the tests were successful in the right bottom corner of eclipse.
If a tests fails the line where it fails is marked as an error so you can keep working with the source files and don't have to wait for your tests and have your workflow interrupted.