本文介绍了在eclipse中找不到run作为junit测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration( location = {classpath:applicationContext.xml})
@TransactionConfiguration
@Transactional
public class TeamTest extends AbstractTransactionalJUnit4SpringContextTests {

@Test
public void testCreate(){


assert(true);
}}

但是,当我点击右键单击文件,我看不到选项以JUnit运行!



有什么问题?



我正在使用Eclipse 3.6

$确保您的eclipse环境正在使用JUnit 4. JUnit 3不使用注释(它使用旧的扩展TestCase 风格)



有两件事需要仔细检查:



窗口>首选项> Java> JUnit



您是否看到 junit4 junit3 进口?如果看起来不错,请确保项目本身正在使用JUnit4而不是JUnit3。



右键单击项目>属性> Java构建路径>图书馆



JUnit4是否包含在那里? JUnit有什么关联吗?如果JUnit3在那里,点击它,然后点击删除。然后点击添加库... ,然后按照提示再次添加JUnit。



出于好奇, JEnits是否在eclipse之外运行?像一个 mvn install 或者你为Ant的任何构建目标,将运行JUnits


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

解决方案

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

这篇关于在eclipse中找不到run作为junit测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 14:03