开发者

can't find run as junit test in eclipse

开发者 https://www.devze.com 2023-02-06 10:34 出处:网络
I created a test class in Eclipse like this @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { \"classpath:applicationContext.xml\" })

I created a test class in Eclipse like this

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:applicationContext.xml" })
@TransactionConfiguration
@Transactional
public class TeamTest exten开发者_JAVA百科ds 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


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...


The way I fixed it is by changing Test runner in the Run Configuration from the default Junit3 to Junit4. Once I made this change I could see the option Junit when I right clicked on the test class and expanded Run As

can't find run as junit test in eclipse


I encountered the same issue and verified all the settings (above mentioned) are fine. A small change (version to 1.5.21.RELEASE from 2.5.0-M2) in pom.xml resolved my issue (below). This Iam able to recreate consistently.

STS Details Version: 3.9.0.RELEASE Build Id: 201707061823 Platform: Eclipse Oxygen (4.7.0)

Pom.xml change

FROM

<modelVersion>4.0.0</modelVersion>
<parent>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-parent</artifactId>
         **<version>2.5.0-M2</version>**
         <relativePath/> <!--  lookup parent from repository  -->
</parent>

TO

<modelVersion>4.0.0</modelVersion>
<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        **<version>1.5.21.RELEASE</version>**
        <relativePath /> <!-- lookup parent from repository -->
</parent>


Make sure you are using Junit as your testing framwork and not something like TestNg which cover most of Junit's purpose.

0

精彩评论

暂无评论...
验证码 换一张
取 消