Don't have option to create the jUnit test class - eclipse

Junit test class option is not listed in eclipse and if I create a normal class and add the #Test annotation it still don't run the test class besides I have imported the junit jar files to my project but still eclipse is not running any test classes, can someone please help?
furthermore when I hit the other option still there is no option to choose Junit

For creating a suite: Choose Other and then choose Java -> Junit -> JUnit Test Suite.
Next page choose between JUnit 3 or 4 and click Finish
You can create Class with JUnit Test by choosing Other and then choose Java -> Junit -> JUnit Test Case.

Related

test Grails 3.3.8 app with junit 4 or 5 in eclipse 2018-12, is it possible?

i m working on a grails project and i want to add tests to it.
I used spock and Geb but i prefer JUnit but it doesnt work.
i m creating a new Groovy Test with the eclipse wizard, i select either junit4 or junit 5
then it creates a new test class
i right click and select run as> Junit Test
it should show the junit view with failing test but no
i get a lot of "Invalid package binding for default import java.util/net/io"
and a "could not retrieve superclass","AbortCompilation ... AssertionError cannot be resolved. it is indirectly referenced from required .class file"
from org.eclispe.jdt.core
and i get an invocationTargetException caused by a NPE from org.eclispe.jdt.junit
those are my last errors from my many attempts, i feel like it s just impossible to do it.
if someone managed to make it work, pls tell how you did it
regards
test Grails 3.3.8 app with junit 4 or 5 in eclipse 2018-12, is it
possible?
Yes, it is. There are numerous ways to do that.
A common way to do that is to create a launch config in Eclipse that will execute the test or integrationTest Gradle task with the appropriate parameters.

How to delete Junit3 support in eclipse?

I am using a freshly downloaded eclipse (eclipse-jee-oxygen-3a-win32-x86_64) from eclipse.org.
When I create a new JUnit Test Case using the wizard, then the wizard allows to add a "New JUnit 3 test".
Additionally when I am inside my test class and want to add a new test method via writing test and hitting Ctrl+Space then the template shown above is "test3".
How can I remove JUnit 3 support completely from my eclipse?
Or even better, since we also use a pre-configured eclipse installed via the eclipse-installer (oomph), how can I avoid to install it in the first place? Our oomph installation is based on package epp.package.jee.
Use eclipse-jee-oxygen-M2-win32-x86_64 from eclipse.org.
You can download it from http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/oxygen/M2/eclipse-jee-oxygen-M2-win32-x86_64.zip
When you will create a new Junit Test Case using the wizard. It will not add Junit 3 support instead It will add Junit 4.

Disable import of JUnit 3 classes

I want to develop JUnit 4 tests only. When writing Unit Tests, Eclipse often imports classes from junit.framework, which is JUnit 3.
This has lead to various problems, e.g. when expecting an Exception, it simply doesn't catch it if it's in the wrong package like this:
import static org.junit.Assert.*;
import junit.framework.ComparisonFailure;
[...]
try
{
assertEquals(0, 1);
}
catch(ComparisonFailure cfe)
{
}
Strange enough, if I Ctrl+Click on ComparisonFailure, it says
Source not found
The JAR of this class belongs to container 'JUnit 4' [...]
Perhaps helpful environment information:
I don't have JUnit 3 in my build path.
Eclipse Luna 4.4.1
How can I stop Eclipse from importing JUnit 3 classes?
I have read Why is Eclipse using JUnit 3 when I have junit-4.3.1.jar in my build path?, but it's rather old and probably does not apply to Luna any more. Also, my problem is not in running the test, it's in implementing the test.
Another workaround for Eclipse's users is the following solution:
Windows -> Preferrences -> Java -> Appearance -> Type filters
and add junit.framework.* to the exclusion list.
Actually, JUnit 4 depends on some of the classes that were developed originally within JUnit 3 or reside in packages junit.*. One of such class is ComparisonFailure. If you look at latest JUnit 4.12 you will see that these packages are still there.
However, sources jar do contain java files for these classes. Perhaps your library that contains JUnit (do you use Eclipse JUnit library?) lacks source files for these? Where does your dependency (junit.jar) come from?
Which dependencies has your plugin ? Junit 3.X or 4.X ?
You could search your workspace for any references in junit 3 and change/remove them.

How to run a JUnit test in eclipse?

I'm using eclipse and I have downloaded a JUnit test, and imported it into my package that I'm currently working on.
However instead of showing test.java it shows test.java.txt. And when I click 'Run as', JUnit test does not come up as one of the options.
Thank you in advance for your help.!
For the "Run as JUnit" option to appear, the file must be a Java file (extension .java).
JUnit scans your class for test methods. Depending on the version of JUnit that you're using, it can be done in multiple ways. JUnit before version 4.0 requires your test methods' names to start with the word test; with JUnit 4.0 onwards, you can use annotations to designate your test methods.
If your code contains JUnit annotations (such as #Test), but JUnit still complains that it can't find any test methods, then it means that you're running JUnit 3.x and not JUnit 4.x.

Running a focused Groovy unit test from SpringSource Tool Suite (STS)

I have a Groovy unit test class that has many unit tests. In the JUnit way I would normally run with the test function selected, but that doesn't work.
How do you run a focused unit test from STS? I know it's possible on the command line, but I'd like to do it from the IDE.
Run the entire suite once: Right-click on the file -> Run as -> JUnit test.
After all of the tests appear, you can terminate the process. Then select the unit test you want to run, right-click -> Run.
Alternatively, open your launch configuration dialog, create a JUnit test launch configuration. Select your project, package, and test class. You can also choose a unit test.