java – junit: no tests found-ThrowExceptions

Exception or error:

I have inherited a Java project and am new to Java development. I feel a good way for me to get comfortable with the code is to write some tests around it. I’m writing my code using IntelliJ.

My existing project has a folder structure like this:


I created a new project that will hold tests for this project. I would like this project to hold both unit and integration tests. Currently, my new project has a structure like this:


The file looks like the following:


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

public class EmailProviderTest extends TestCase {

    private final String username = "[testAccount]";

    private final String password = "[testPassword]";

    public void thisAlwaysPasses() {

This project has a Run/Debug configuration with the following properties:

  • Test kind: All in package
  • Search for tests: In whole project

When I run this configuration, I get an error that says:

junit.framework.AssertionFailedError: No tests found in
    at org.junit.runners.Suite.runChild(
    at org.junit.runners.Suite.runChild(
    at org.junit.runners.ParentRunner$
    at org.junit.runners.ParentRunner$1.schedule(
    at org.junit.runners.ParentRunner.runChildren(
    at org.junit.runners.ParentRunner.access$000(
    at org.junit.runners.ParentRunner$2.evaluate(
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(
    at com.intellij.rt.execution.junit.JUnitStarter.main(
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(
    at com.intellij.rt.execution.application.AppMain.main(

I do not understand why I’m getting an error that boils down to: “No tests found”. While my project structures differ, the folder structures on the OS match (which is another thing that confuses me). Why am I getting this error and how do I fix it?

How to solve:

I was getting error too

junit.framework.AssertionFailedError: No tests found in …

But I’ve forgot to specify

defaultConfig {
    testInstrumentationRunner ""

After sync projects it found tests. So maybe it helps someone else


Extending junit.framework.TestCase is the old JUnit 3 approach of implementing test cases which doesnt work as no methods start with the letters test. Since you’re using JUnit 4, just declare the class as

public class EmailProviderTest {

and the test method will be found from the @Test annotation.

Read: JUnit confusion: use ‘extend Testcase’ or ‘@Test’?


I was getting this too:

junit.framework.AssertionFailedError: No tests found in …

Solved by renaming the test method from method1

public void method1(){
    // Do some stuff...

to testMethod1

public void testMethod1(){
    // Do some stuff...


if you are using jUnit 4 then not use extends TestCase, removing this fixed error.


I had the same issue, in Intellij IDEA, for Java framework.
I was doing all right:

  • the class inherited from TestCase
  • I’ve imported junit.framework.TestCase
  • I’ve add the decoration @Test

But I did one thing wrong: the name of the method didn’t start with “test”, in fact was:

public void getSomethingTest(){

and when I changed it into:

public void testGetSomethingTest(){

I’ve resolved: the executor was finally able to recognize this method as a test method.
I’ve changed nothing else.


I bumped into the situation in JUnit 5 when created a private method:

import org.junit.jupiter.api.Test

class Test1 {

    private fun sort() {

Remove private.


I had it when using data provider and one of the parameters had a new line character, like this:

public static Object[][] invalidAdjustment() {
    return new Object[][]{
            {"some \n text", false},

Removing the \n solved the issue


In my case, I needed junit4-version.jar in the classpath of the task junit and also:


at the library of my ant installation (/usr/share/ant/lib).

I was getting the error “junit.framework.AssertionFailedError: No tests found in …” while I hadn’t had ant-junit4-*version*.jar in the right place.

I corrected this by installing ant-optional debian/ubuntu package:

apt-get install ant-optional


I was fretting with this and none of the answers helped me until i moved the test source file from this folder:


up to this folder:



The other reason generally i see people having method parameters, remove any parameters you might have in the test method, regardless you add @Test annotation , you need to have your method name starting “test” in order for Junit to pick you testcase.
hope it helps.


Test method name public void testName() {}

Where name() in source naming name methods.

Leave a Reply

Your email address will not be published. Required fields are marked *