JUnit test classes are not coming while creating JUnit test suit
I tried to create JUnit Test Suite in eclipse by following the steps- Right click on the source folder -> New -> Other -> JUnit Test Suit. The issue is I am not getting the test classes under the comment 'Test classes to include in suite'(no class is there) even though I have created Java application and corresponding JUnit test classes under the source folder.
In my source folder under default package - Application name - test.java JUnit test class - testTest.java and testTest1.java
As the JUnit test classes are not coming under the comment 'Test classes to include in suite', I am unable to create JUnit Test Suite.
Can anybody please help me to resolve this issue as I am new to开发者_如何学Go JUnit?
When you were creating the JUnit Test Case make sure you are choosing the correct JUnit test option at the top of the New JUnit Test Case menu. For example there are test choices such as "New JUnit 3 test", "New JUnit 4 test", and "New JUNit Jupiter test". I have the best results choosing the "New JUnit 4 test". then you should name it accordingly and see the test added to your options when creating a new JUnit test Suite.
Which versions of Eclipse and JUnit are you using? If you are new to JUnit I would recommend using version 4, which uses annotations to define test methods instead of having to subclass TestCase
. However, in versions of Eclipse up to 3.6 (Helios) the test suite wizard does not recognize JUnit 4 test cases.
It looks like this has been fixed in version 3.7 (Indigo) although I have not tried it myself: https://bugs.eclipse.org/bugs/show_bug.cgi?id=155828
You can define a test suite by hand if you want to: Junit4 Test Suites
You might also find you can live quite happily without ever creating a test suite! To run all test cases in a package in Eclipse you can just right click the package and "Run as JUnit test". For automated testing as part of a build I use Ant to run all test case classes with names matching a given pattern.
Make sure there is no .APi in the import package,
I was facing the same problem, got resolved.
Take a look at all the import
statements (I'm using Eclipse Oxygen)
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import jdk.nashorn.internal.ir.annotations.Ignore;*
public class TS_sample {
@Before
public void btest() {
System.out.println("Before test");
}
@Test
public void test1() {
System.out.println("In test1");
}
@Ignore
public void test2() {
System.out.println("In test2");
}
@Test
public void test3() {
System.out.println("In test3");
}
@After
public void atest() {
System.out.println("After test");
}
}
精彩评论