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.
Related
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.
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.
I have Playframework 2 project with Scala (very small one). It uses Scala Anorm library.
I have the code like this:
package models
..
import anorm.SqlParser._
...
val rowParser = scalar[Long]
So, I would like to see source of scalar method. Trying to attache the sources I have in my plaframework source folder, but IDEA just swallows my request and does nothing back.
I use last version of IDEA and Scala plugin. Is it bug, probably?
First download source code :
1.) Click on this link : http://www.scala-lang.org/download/all.html
2.) Choose any scala version.
3.) Now in the last section 'Other Resources' you can see 'Sources' link. Click on it to download. In my case (https://codeload.github.com/scala/scala/tar.gz/v2.11.7)
Now point to this Source Code from IntelliJ.
1.) Open Project Structure in IntelliJ. Shorcut (Cmd + DownArrow)
2.) Select Global Libraries from the left section.
3.) Then on right side, Under 'Scala Library' section. Click '+' and point to source directory. See the screenshot.
Aha.. fixed.
So: I used to use 'attach source' in the top of the window editor - it does not work (I guess it is a bug - maybe related to the scala plugin, because usually it works).
But if try to attache sources to particular library - in "Project Structure -> Library -> +Attach File or Directories -> Sources" then it works.
Thanks.
To fix it we need to do some changes into IntelliJ IDEA platform. Most probably it will be fixed in IntelliJ IDEA 13.1.
I have the same problem. I installed "Scala Imports Organizer", and problem was solved.
for "automatically attaching source jars" when using Bloop and BSP you can add one line:
bloopExportJarClassifiers in Global := Some(Set("sources"))
to your build.sbt, also sbt updateClassifiers, also Reload all BSP Projects to refresh, also Invalidate Caches/Restart to trigger indexing (if not done automatically)
reference
I am using Netbeans 7.0.1 with a web project that I have imported from existing sources. I have added the JUnit library to my project. In Netbeans tutorials online for version < 7 it says to create a JUnit test for a given existing class by righ-clicking on the source file in the project, select the menu "Tools" and then there should be an option to create a JUnit test. However this option does not appear for me. There seem to bean old bug report/request for functionality, describing this but it does not seem to have been resolved as it is mentioned as late as 2011-05-09 on the Netbeans bugzilla list (link Related on bugzilla). On the bugzilla it is suggested to explicitly create the folder /test/unit/src in the project, but still after this when I try to create JUnit test for an existing class from rightclick project -> new -> other -> JUnit, I get "no tests root folder was found in the selected project" (I tried changing the foldername to tests as well). Can I explicitly set this location in some configuration file and is there any way of getting the expected functionality allowing me to simply righclick a source file and select "JUnit test" to create a JUnit stub for the selected class ?
If you right click on the project and pick "Properties" you should see "Sources" on the left. Select that and then click "Add Folder..." under the "Test Package Folders" section. This will add a new test directory. If you have an existing one, delete it first (just make sure the test sources are saved somewhere else) and then add the new one.
If you right click on your project and add new Unit Tests-> JUnit Test it will automatically create the path for you.
if src/main/java is missing, netbeans 8 does not let you create test case in src/test/java using the wizard
looks like a bug, still valid in 2015
What kind of project you've made has a large effect on whether there's a test root already or no. In Netbeans 7.1.1, a "POM Project" doesn't create a test root directory as a part of the project build process. However, making a Java Application did make a test root by default.
I tried the directions offered by mamboking and I wasn't able to change the directories in the Sources section of the project properties. Making a new project of type "Java Application" make the correct test root.
I'm using eclipse to run the tests in a single junit(4) test class. The tests in the class all run just fine. Then I add an additional test and run the class through the test running in ecplise again. Only the old tests are run. The new test isn't seen by eclipse. There's no error or anything, it's just as if eclipse is looking at an old version of the test.
If I run the tests using maven, everything works fine. Additionally, after I run the tests in maven, ecplipse can see and run the new test correctly.
Any ideas what's going on? Any ideas how to get ecplipse's test runner to see my new test cases?
I had the same issue. I solved it by doing the following:
Going to Project -> Properties -> Java Build Path
For the source folder src/test/java, the output folder was set to
"Default output folder"
Setting this to the typical Maven target/test-classes directory in your Maven structure
After this, Maven and Eclipse were in sync (as opposed to Eclipse happily running an older version of the tests, from whenever the last Maven compile was).
Maybe you "just" need to create a new Run configuration. Eclipse "remembers" the latest used Run configuration and just repeats it if not told otherwise. To make sure you have a new Run Configuration you can rightclick the test case in the package explorer and choose Run As | Junit Test. Next time you hit play this will be the "remembered" Run configuration etc.
Possibly src/test is not in the Java Build Path.
Solution on Kepler:
Project -> Build Path -> Configure Build Path -> Source -> Add Folder
Then check the box corresponding to test under src
You might find this is likely caused by using Maven to build (Maven usually builds into the 'target' folder), but Eclipse is using a different build folder for its own build process. Simplest way is to go into the target folder under your Eclipse Project (or Bundle if using OSGi) and delete the conflicting subfolders/class-files from under that directory; for me this is my "target" folder. Then get Eclipse to rebuild, and everything should be fine.
Technically, and alternatively, you could just blow away the entire build/target folder if you wanted to, and let Eclipse rebuild everything.
In response to the answer provided by Ryan Dawe, I have found out that Default output folder can be set to only one folder, for all the source folders on build path. So if i changed the output folder to target/test-classes, my src/main/java was also outputting classes there.
You might have written this response for a different older version of eclipse, but as of Mars.2 release, we can only have one default output folder for all source folders.
The best solution i have found so far for this problem is to just include the target/test-classes as a class folder, by going to Project -> Properties -> Java Build Path -> Libraries -> Add Class folder.
It seems that your project wasn't recompiled. Either check Menu:Project/Build Automatically or do it manually as Boris Pavlocic commented.
This seems to be the same issue as junit not using the newest file
The problem seems to be that Eclipse puts the compiled tests in the wrong folder which can be solved by manually specifying where they should end up.
Add "test" in front of your test classes if not there already the #Test annotation isn't always picked up from Eclipse's Junit Test framework.
Here is how i fixed my problem...
right click project and go to Run As -> Run Configurations...
select JUnit -> [project-name] on the the popup that came up
(this configuration of [project-name] was created for me by eclipse
but if not there you can right click JUnit -> New and create it)
goto Classpath tab
highlight User Entries and click Advanced... button
on the Advanced Options popup that came up select Add Folders and click OK
on the Folder Selection popup that came up scroll to your project open up target and select test-classes and click OK
repeat steps 4-6 for the [project-name]/target/classes directory and any other directory needed in your classpath (like properties files used in your tests etc.)
Note: this assumes your project's default output folder for tests is target/test-classes, if it is not then adjust accordingly. Also, make sure you have the right JUnit version selected under the JUnit Run Configuration as well and your src/test/java directory is a source folder to your project, etc. as mentioned by others.
It means that you have created a Test class that you haven´t build yet.
After a build, for example with "gradle build" the Test class will be found by Eclipse too.
In my case I had to make a cleanup before as well.