junit test cannot be resolved to a type after adding junit jar file - junit4

I want to create a simple Junit test. However, after I buildpath using Eclipse for Junit4, it still give me an error: junit test cannot be resolved to a type for:
JunitTesting class
Please see my screenshot for setting:

Related

Cannot "Run as JUnit Plug-in test" on test plugin/package (JUnit5)

I'm trying to add JUnit5 support in my Eclipse RCP application. It almost works, because for now I can:
Use Maven to build whole application and run tests with Tycho
Run single JUnit5 tests (creating run configuration on specific class) in
Eclipse
Run single JUnit5 tests in Run as JUnit Plug-in test mode in Eclipse
Run multiple JUnit5 tests in Run as JUnit test mode in Eclipse
What I'm trying to achieve now is to be able to run whole sets of test classes in plug-in test mode. For JUnit4-based plug-ins I could simply right-click on whole package or even whole plug-in and invoke Run As -> JUnit Plug-in test.
When I do the same operation on JUnit5 tests I get an error: No tests found with test runner 'JUnit 5'.
My current configuration for such plug-ins looks as follows:
According to official instructions in MANIFEST.FM I have Import-Package dependencies:
org.junit.jupiter.api,
org.junit.jupiter.params,
org.junit.jupiter.params.provider
and org.junit as Require-Bundle dependency
In order to run tests in Eclipse IDE I've also added JUnit 5 library to Java Build Path of the plugin. I coudn't add JUnit 5 runner dependencies to MANIFEST.FM instead, because of conflict with Tycho.

JUnit5 tests work fine with maven but not when run through Eclipse, "No tests found with test runner 'JUnit 5'."

I'm getting a pop-up window with title "Could not run test" and message "No tests found with test runner 'JUnit 5'." when I try to run JUnit 5 tests with Eclipse via Run As > JUnit Test.
I have two test-related files. One is a test suite:
...
import org.junit.jupiter.api.BeforeAll;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.platform.suite.api.SelectPackages;
import org.junit.runner.RunWith;
#RunWith(JUnitPlatform.class)
#SelectPackages("com.foo.stufftotest")
public class TestSuite {
#BeforeAll
public static void setup() {
...
The other contains the "actual" tests:
package com.foo.stufftotest;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
import com.foo.TestSuite;
import com.foo.business.mechanics.LogicStuff1;
public class BusinessTest {
#Test
public void testLogic1() {
...
}
#Test
public void testLogic2() {
...
}
...
All the testLogicN() methods depend on setup stuff done in TestSuite.setup(). If setup() doesn't run, there are a lot of null values, and it's no surprise that things fail. When I try to run JUnit from the project's context menu, all the tests are triggered and they all fail; the suite doesn't seem to be recognized. When I try to run JUnit specifically from TestSuite.java's context menu, I end up with the error I mentioned at the top of the question.
However, when I run maven test on the project, the suite is triggered properly, and all the tests pass. Therefore, the code itself doesn't seem to be the problem.
I don't remember having this issue with JUnit 4, although I never used JUnit 4 with this particular project.
Am I using Eclipse wrong, or am I using JUnit5 wrong? What's the fix here?
I encountered the same issue in Eclipse Oxygen 4.7.1 despite the fact that my unit tests were properly annotated with org.junit.jupiter.
I used the Maven > Update Project and selected Update project configuration from pom.xml but that did nothing even though I thought it would pick up the fact that I had JUnit5 dependencies in the pom.
My solution:
Open Java Build Path, select Libraries tab and Add Library.
Select JUnit.
Select JUnit5 for JUnit library version.
Once added I was able to manually execute tests from Eclipse. However I'm still not certain why this was not added automatically.
I'm getting a pop-up window with title "Could not run test" and message "No tests found with test runner 'JUnit 5'." when I try to run JUnit 5 tests with Eclipse via Run As > JUnit Test.
That's because TestSuite is in fact not a JUnit 5 test class. Since it is annotated with #RunWith (from JUnit 4) it is a JUnit 4 test class. To avoid the pop-up window in Eclipse, simply click on "Run Configurations" and select JUnit 4 instead of JUnit 5 for running the test class.
The other issue you have is that #BeforeAll is an annotation from JUnit Jupiter. Thus, it is simply not supported in a class annotated with #RunWith(JUnitPlatform.class) (unless that class also happens to contain #Test methods for JUnit Jupiter). Thus you will have to find an alternative approach to executing your "set up" code.

Eclipse error - Cannot be resolved to type

Created a Maven Project and have set the dependencies in the pom.xml. The import statement (com.splunk.*) seems to recognize the library included in the Maven Dependencies, however when I refer to the class (for e.g. ResultsReaderXml) within that library, it shows the "error message cannot be resolved to type". Can some please explain why Spring Tool Suite (Eclipse) is doing that?
https://i.stack.imgur.com/enCRW.png

Tests in a maven project do not run with Netbeans but run fine with Eclipse. maven-surefire-plugin

so essentially I have a big maven project. When I open it in netbeans, strangely if I add any new junit test class or even if I rename existing test classes I cannot run any of them using "Test File", but old test classes run fine. I receive a message:
Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.14.1:test (default-cli) on project sga: No tests were executed! (Set -DfailIfNoTests=false to ignore this error.) -> [Help 1]
Strangely, if I open the same project with Eclipse, all new and renamed classes run fine without errors with "Run As JUnit".
Could help me to make the new tests run in netbeans? Thank you

ClassNotFoundException: Running JUnit Tests in Eclipse

I have a project with src, classes & tests. I keep my JUnit tests in the tests folder.
I keep getting a ClassNotFoundException while running them in Eclipse.
I tried running them using from the Command line.
javac -d classes src\brick\*.java test\brick\*.java
The compiler reports 20 errors telling me that the package org.junit does not exist.
Could anybody help me?
Thanks.
What are you using to manage your dependencies (maven, contained in a lib dir)? Are all of the necessary jars in your classpath?
Javac needs to know where your JUnit jar is located in order to compile your classes.
You should try something like:
javac -cp <path to junit jar> -d classes src\brick\*.java test\brick\*.java
When in Eclipse, you need to add the JUnit jar to your project. Normally this is
done automatically if you have a test case...