Managing unit test for Eclipse CDT - eclipse

Eclipse CDT can produce a filename_test.cpp for each filename.cpp I write.
This is supposed to be used with some kind of unit test.
I have written a few tests using "Google test" (gtest) and I know they are working because I hand-compiled them from the command line.
Question is: How do I convince Eclipse to compile them and, if possible and in case something goes wrong, let me debug the test to understand where I goofed?
From this question I seem to understand I need to prepare a series of "Build Targets" most likely one for each test, but it's unclear to me how I can do it; doing [right-click on Project] -> "Build Targets" -> "Create..." I can select one predefined target, but I didn't find how to actually define the recipe to build (I'm currently using "Managed build"), sources to test and libs.
What is "best practice" here?

Related

what is the right way of importing a maven project in Eclipse and run it as a Java project?

I don't understand exactly what is the way of working with maven projects in Eclipse.
The problems I have are often with projects I download from github. If I set the project myself it usually work, so I think I'm doing something different from the majority of people.
I'll try to detail a specific case:
I clone a repo, let's say: https://github.com/spring-guides/tut-spring-boot-oauth2
In Eclipse I import "existing maven project"
The project has a "Maven nature" as indicated by M on the folder icon
I try to run java class with main from Eclipse. First strange thins is that the "Run As" menu doesn't have "Run as a Java application"
I have to configure the configuration manually. Now it runs, but strange things happens, like I can't edit the file as the "content assist" throw errors instead of giving the normal assists.
I notice that the project has no "source folder". So my first instinct is to add a Java nature or select src as source folder
So I add Java nature to the project. This is a disaster. It can compile anymore as it can find packages. All classes have errors. I try to play around setting source folders on /src or /src/main/java. Sometimes I fix the errors but I can't run (and now I have run as Java application) but when I run it can't load the class
So in the end, I'm a bit confused and I don't know if I explained clearly what I'm doing.
I think I would like to know in a simple way how people are doing it, rather than trying to correct my steps as I'm probably creating a mess myself.
Any help or suggestion welcome.
I'm using the last version of eclipse. I don't know which other tool's versions are relevant.
P.S. I also refresh,restart,clean rebuild the project often after touching things...but it doesn't get better
Maven is a build (management) tool. Simply spoken, its task is to create a JAR that can be used as a dependency/library by other projects or when running java -jar ....
Running a project's code isn't part of it (apart from unit and integration tests code and by using non-default plugins for special situations). Running code is part of Eclipse (or any other IDE) with its Run Configurations.

Running scala tests in IntelliJ

I want to debug a variable in scala metadata.sparkVersion in KMeans.scala using scala test suits in spark KMeansSuite.scala.
I have set my break point. However when I try to run (Or right click) it, I dont see a Run option. How do I fix this?. How should I go about debugging the code.
Please follow the tutorial. You need Scala plugin if you want Idea to undestand ScalaTest. If it is already done:
Right click on test folder and "Mark directory as"-> "Test Sources Root".
Alternative is to annotate the test with
#RunWith(classOf[JUnitRunner]) see here
Then the tests will be executed with JUnit
Or you can have JUnit tests

My jar won't add my junit tests

The contents of my jar file does not contain my junit tests. I tried creating a main class that calls my tests with "Junit Core" but that too doesn't get added to my jar file. What am I missing?
Your production package (your jar) is not supposed to contain the test code (your unit tests).
Test code is supposed to be invoked only when the tests are been executed.
You shouldn't do it, but if you want the test code to be included in your package just put it in the same root folder of your production code. Ex: if you are using Maven, your folders structure might be something like this:
project_name/src/main/java/
-> production code
project_name/src/test/java/
-> test code
In that case, change it to:
project_name/src/main/java/
-> production code
-> test code
Be aware that doing that you will have some problems, like the tests not executing during a normal build. We might help you better if you put a question asking how to accomplish your goal (what is your goal?).
Update based on the goal explained in the comments: Would be better if this tool (Silk Central) could run your tests using Maven or Ant, and I'm pretty sure it can.
I've been used different tools to run my Junit (or other XUnit frameworks) tests. What I do is to configure the tool to:
Get the source code from the version control.
Run the build/tests by calling Maven or Ant installed along the tool.
Read the Junit outputs.
Sometimes the tool has its own integration with Junit and you don't have even to use Maven or Ant.
I mean, your central build or tests tool should be able to run your tests just like you do in your own machine.
Take a look on this or search by "Silk Central junit" in the web:
http://community.microfocus.com/borland/test/silk_central/w/wiki/465.zero-maintenance-junit-testing-using-classpathsuite-in-sctm.aspx

Eclipse: don't build if their are unsolved warnings

Is their a way to prevent Eclipse from building or compiling a project if unsolved warnings exist? I'm very lazy and know I am likely to ignore feedback from tools like checkstyle, so I was thinking it could be useful to force correct code before compiling.
Do you think this is a good idea? Do you know how I might do this in eclipse?
Thanks.
Eclipse
In the Preferences window, under Java|Compiler|Errors/Warnings, each of the various types of problems can be set to Ignore, Warning, or Error. You can change any or all of them to Error.
At the bottom of the page is a checkbox for:
Treat above errors like fatal compile errors (make compiled code not executable).
So, decide what messages you want to fail your build, and check that last checkbox.
Non-Eclipse Use
If you want to use checkstyle, findbugs, or pmd and have them fail your build, you will have to depend on an external build tool like Ant, Maven, or Gradle. You can create <checkstyle>, <findbugs> or <pmd> tasks, and have your real <package> target depend on them; that way if the audit task requires compilation, the target allows it, but you'll never get a [ejw]ar file out of it.
It's actually a good idea to have a build system that does not depend on the IDE. You may want to use a CI system, for example.

Is there a problem-free way to run Scala 2.7.7 unit tests in Eclipse integrated nicely?

I'm developing Scala code using Eclipse, often when I run tests I get this error:
No tests found with test runner 'JUnit 3'.
Environment:
Eclipse for Java Developers, 3.5.1
Scala 2.7.7
JUnit 4.7
I'm currently writing my tests as JUnit3 tests, and invoking them by right clicking on a package in the project explorer, choosing Run As -> JUnit Test. (I was writing them as JUnit4 tests but ran into even more problems.)
If I fire up eclipse, the tests may not run unless I first open the source code file for the test. If I do open the source code file for the test, it will run. However, often then when I make any modification to the test file or any other source code file, Eclipse will refuse to run my tests, saying: "No tests found with test runner 'JUnit 3'."
I just repeated this just now:
Open eclipse
Open the .scala file with some tests
Invoke the tests by right clicking on the package for that file in the project explorer and choosing Run As -> JUnit Test
It ran the tests
One failed
I changed a string literal in the failing test to fix it
I then re-launced the test using the same method, and I get the dreaded "No tests found with test runner 'JUnit 3'."
I get this same method using other methods of launching the tests, e.g. JUnit buttons or menus to re-run all or some tests
To get the tests to run again I close and re-open Eclipse... So I end up relaunching Eclipse many many times a day.
Note: I do often use XML literals in my tests, I wonder if that has anything to do with it.
2nd Note: See my answer to this thread: What is the current state of the Scala Eclipse plugin? where I described some of the other problems I'm having with Scala+Eclipse. Most of the problems are just minor annoyances, but this test invocation problem is a real time waster, would love to find a way around it!
This Just works on trunk ... JUnit 3 and 4 unit test are detected and Run As => JUnit test does the right thing.
Oh, and BTW, the best way to get my attention on this sort of thing is to file a bug or enhancement ticket in Trac rather than posting messages to StackOverflow (even though it worked this time ;-)