Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can't find run as junit test in eclipse

I created a test class in Eclipse like this

@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { "classpath:applicationContext.xml" }) @TransactionConfiguration @Transactional public class TeamTest extends AbstractTransactionalJUnit4SpringContextTests {   @Test  public void testCreate() {     assert (true);  }} 

However, when I click right click on the file I don't see option to run as JUnit!

What is wrong?

I am using Eclipse 3.6

like image 996
Dejell Avatar asked Jan 25 '11 14:01

Dejell


People also ask

Why Eclipse is not showing as JUnit?

That kind of J icon filled to a "bubble" means that Eclipse doesn't recognize your project as a Java project, and therefore doesn't provide Java options such as Run as JUnit. Try reimporting the project as a Java Project.


2 Answers

Make sure your eclipse environment is using JUnit 4. JUnit 3 doesn't make use of annotations (it uses the old extends TestCase style)

There are few things to double check:

Window > Preferences > Java > JUnit

Are you seeing junit4 or junit3 imports? If that looks good, make sure the project itself is using JUnit4 instead of JUnit3.

Right Click on project > Properties > Java Build Path > Libraries

Is JUnit4 included there? Is anything JUnit related there? If JUnit3 is in there, click on it and click Remove. Then click Add Library... and follow the prompts from there to add JUnit again.

Out of curiosity, are the JUnits run outside of eclipse? Like with a mvn install or whatever build target you have for Ant that'll run JUnits

like image 63
brian-d Avatar answered Sep 17 '22 23:09

brian-d


Write a simple test case to see if Eclipse works correctly or not. If simple test case can be run, check your testcase, especially import classes.

Or make a try in "Run" -> "Run Configurations",fill the "Test class" as "TeamTest"(full class name). Then click "Run", see what will happen...

like image 35
卢声远 Shengyuan Lu Avatar answered Sep 20 '22 23:09

卢声远 Shengyuan Lu