No tests found for given includes: JUNIT

Artur Vartanyan :

I wrote a test for my method from the service, but the test won't run. Gives an error message! I did everything strictly according to the guide, I did not add anything new. There are few solutions to this problem on the Internet. What could be the problem?

P.S. I tried changing in runner settings -> test runner -> Gradle / Intelij Idea - not works.

Testing started at 17:43 ...

> Task :compileJava UP-TO-DATE
> Task :processResources UP-TO-DATE
> Task :classes UP-TO-DATE
> Task :compileTestJava
> Task :processTestResources NO-SOURCE
> Task :testClasses
> Task :test FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':test'.
> No tests found for given includes: [ru.coffeetearea.service.OrderServiceTest.setOrderService](filter.includeTestsMatching)
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at
4 actionable tasks: 2 executed, 2 up-to-date


plugins {
    id 'java'

group = 'com.example'
version = '0.0.1-SNAPSHOT'

sourceCompatibility = '1.8'

repositories {

// Без этих опций Mapstruct выдает ошибку на кириллицу!
compileJava.options.encoding = 'UTF-8'
compileTestJava.options.encoding = 'UTF-8'

dependencies {
    // Thymeleaf
    implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-thymeleaf', version: '2.3.3.RELEASE'
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-validation', version: '2.3.3.RELEASE'
    // Swagger UI
    compile group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.9.2'
    // Swagger 2
    compile group: 'io.springfox', name: 'springfox-swagger2', version: '2.9.2'
    compile group: 'org.springframework.boot', name: 'spring-boot', version: '2.3.1.RELEASE'
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: '2.3.1.RELEASE'
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-jdbc', version: '2.3.1.RELEASE'
    compile group: 'org.postgresql', name: 'postgresql', version: '42.2.14'
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.3.1.RELEASE'
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: '2.3.1.RELEASE'
    compile group: 'org.flywaydb', name: 'flyway-core', version: '6.5.1'
    // MapStruct
    implementation 'org.mapstruct:mapstruct:1.3.1.Final'
    annotationProcessor 'org.mapstruct:mapstruct-processor:1.3.1.Final'
    compileOnly 'org.projectlombok:lombok:1.18.12'
    annotationProcessor 'org.projectlombok:lombok:1.18.12'
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-security', version: '2.3.2.RELEASE'
    compile group: 'io.jsonwebtoken', name: 'jjwt', version: '0.9.1'
    compile group: 'javax.xml.bind', name: 'jaxb-api', version: '2.4.0-b180830.0359'

    testCompile group: 'org.mockito', name: 'mockito-junit-jupiter', version: '3.5.10'
    testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: '2.3.3.RELEASE'


    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'

test {

method makeOrder():

public OrderDTO makeOrder(MakeOrderDTO makeOrderDTO) {

        Long userId = JwtUser.getCurrentUserID();

        Order order = orderRepository.findByUserIdAndOrderStatus(userId, OrderStatus.NEW);

        if (order == null) {
            throw new MainNullPointerException("Ошибка! Ваша корзина пуста!");
        order.setDateOrder(new Date());

        return orderMapper.orderToOrderDTO(order);

My tests for method:

package ru.coffeetearea.service;

import org.junit.Assert;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.junit4.SpringRunner;
import ru.coffeetearea.dto.MakeOrderDTO;
import ru.coffeetearea.dto.OrderDTO;
import ru.coffeetearea.mappers.OrderMapper;
import ru.coffeetearea.model.Order;
import ru.coffeetearea.repository.OrderRepository;

class OrderServiceTest {

    private OrderRepository orderRepository;

    private OrderMapper orderMapper;

    private OrderService orderService;

    public void setOrderService(OrderService orderService) {
        this.orderService = orderService;

    void makeOrder() {

        MakeOrderDTO makeOrderDTO = new MakeOrderDTO();

        OrderDTO orderDTO = orderService.makeOrder(makeOrderDTO);


ingrese la descripción de la imagen aquí

Guilherme Alencar :

I believe it may be related to your folder hierarchy.

Try to make your test folder hierarchy exactly the same as you src folder. Example:

ingrese la descripción de la imagen aquí

Asegúrese de haber configurado la estructura de su proyecto con las fuentes correctas. Vea la imagen de la configuración de intellij para la estructura del proyecto (haga clic derecho en proyecto> abrir configuración del módulo> módulos> fuentes)

ingrese la descripción de la imagen aquí

Este artículo se recopila de Internet, indique la fuente cuando se vuelva a imprimir.

En caso de infracción, por favor [email protected] Eliminar

Editado en

Déjame decir algunas palabras

Iniciar sesiónRevisión de participación posterior

Artículos relacionados

Cómo implementar JUnit 4 tests JUnit parametrizado en 5?

Resolve Spring @Value expression in JUnit tests

JUnit adding extra tests to Test Case

Running JUnit Tests on a Restlet Router

How to run all my inner class junit tests at once

Spring Parameterized / Theories JUnit Tests

¿Puede ejecutar JUnit Tests para una aplicación CLI?

System.setProperty in JUnit tests

Unable to access test resources from junit tests

Surefire does not exclude JUnit 5 tests marked with @Tag

Assertion dans les tests Java JUnit

Why JUnit tests are failing in Ant Build System?

Exécuter des tests JUnit avec SBT

Android JUnit tests can't call any android api?

Tests junit paramétrés avec plus d'un test

Comment configurer la journalisation JUL pendant les tests JUnit?

Objet compagnon partagé par Kotlin dans les tests Junit

Page not found (404) - No Product matches the given query

No tests found for given includes after upgrade to Gradle 5.1.1

Tests non exécutés avec Junit 5 et Maven

Junit5 and Instrumentation Tests running when running unit tests

How to create objects for all JUnit tests?

.includes () в логике пустой строки

Использование функции includes () в этом случае

«Объект не поддерживает свойство или метод 'includes'» - [ошибка объекта]

Использование логического оператора в .includes () - получение ошибки

Поиск по тегам с помощью includes ()

Использование .includes для поиска подмассивов

Проверка проблемы с проверкой того, совпадает ли ввод пользователя (ответ на вопрос викторины) с одним из правильных ответов в моем вложенном массиве с использованием .includes

TOP Lista