0

Part of pom.xml dependency is pasted below

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.13.2</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

Pasting the contents of a TestFile that works.

Location: ~/IdeaProjects/mavenproject1/src/test/java/FirstPackage/EmployeeTest.java


import junit.framework.TestCase;
import org.junit.Test;

public class EmployeeTest {
    Employee e = new Employee();
    @Test
    public void SayNothing() {
        TestCase.assertEquals("hello",e.getEmployee("hello"));
    }
}

Notice how the call to assert is TestCase.assertEquals. This works and test passes.

When I change the above code to extend TestCase class, I get an error that no tests are found. Why is that?(It is not a compilation error but runtime error)

Broken class

package FirstPackage;

import junit.framework.TestCase;
import org.junit.Test;

public class EmployeeTest extends TestCase{
    Employee e = new Employee();
    @Test
    public void SayNothing() {
        assertEquals("hello",e.getEmployee("hello"));
    }
}```

**Notice the extends TestCase and call to assertEquals without className**

Getting the below error and not sure why

junit.framework.AssertionFailedError: No tests found in FirstPackage.EmployeeTest

at junit.framework.Assert.fail(Assert.java:57)
at junit.framework.TestCase.fail(TestCase.java:227)
at junit.framework.TestSuite$1.runTest(TestSuite.java:97)
at junit.framework.TestCase.runBare(TestCase.java:141)
at junit.framework.TestResult$1.protect(TestResult.java:122)
at junit.framework.TestResult.runProtected(TestResult.java:142)
at junit.framework.TestResult.run(TestResult.java:125)
at junit.framework.TestCase.run(TestCase.java:129)
at junit.framework.TestSuite.runTest(TestSuite.java:252)
at junit.framework.TestSuite.run(TestSuite.java:247)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:86)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:232)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:55)

Process finished with exit code 255

curiousengineer
  • 2,196
  • 5
  • 40
  • 59

0 Answers0