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 https://help.gradle.org
BUILD FAILED in 1s
4 actionable tasks: 2 executed, 2 up-to-date

build.gradle:

plugins {
    id 'java'
}

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

sourceCompatibility = '1.8'

repositories {
    mavenCentral()
}

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

dependencies {
    // Thymeleaf
    implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
    // https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-thymeleaf
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-thymeleaf', version: '2.3.3.RELEASE'
    // https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-validation
    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'
    // https://mvnrepository.com/artifact/org.springframework.boot/spring-boot
    compile group: 'org.springframework.boot', name: 'spring-boot', version: '2.3.1.RELEASE'
    // https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-jpa
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: '2.3.1.RELEASE'
    // https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-jdbc
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-jdbc', version: '2.3.1.RELEASE'
    // https://mvnrepository.com/artifact/org.postgresql/postgresql
    compile group: 'org.postgresql', name: 'postgresql', version: '42.2.14'
    // https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.3.1.RELEASE'
    // https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-jpa
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: '2.3.1.RELEASE'
    // https://mvnrepository.com/artifact/org.flywaydb/flyway-core
    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'
    // https://mvnrepository.com/artifact/org.projectlombok/lombok
    compileOnly 'org.projectlombok:lombok:1.18.12'
    annotationProcessor 'org.projectlombok:lombok:1.18.12'
    // https://mvnrepository.com/artifact/org.hibernate.orm/hibernate-jpamodelgen
    annotationProcessor('org.hibernate:hibernate-jpamodelgen:6.0.0.Alpha5')
    // https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-security
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-security', version: '2.3.2.RELEASE'
    // https://mvnrepository.com/artifact/io.jsonwebtoken/jjwt
    compile group: 'io.jsonwebtoken', name: 'jjwt', version: '0.9.1'
    // https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api
    compile group: 'javax.xml.bind', name: 'jaxb-api', version: '2.4.0-b180830.0359'

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

    testImplementation('org.junit.jupiter:junit-jupiter:5.4.0')

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

test {
    useJUnitPlatform()
}

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.setTotalCost(calculateOrderPrice(order));
        order.setAddress(makeOrderDTO.getAddress());
        order.setPhoneNumber(makeOrderDTO.getPhoneNumber());
        order.setDateOrder(new Date());
        order.setOrderStatus(OrderStatus.ACTIVE);

        orderRepository.save(order);

        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;

@RunWith(SpringRunner.class)
@SpringBootTest
class OrderServiceTest {

    @MockBean
    private OrderRepository orderRepository;

    @MockBean
    private OrderMapper orderMapper;

    private OrderService orderService;


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


    @Test
    void makeOrder() {

        MakeOrderDTO makeOrderDTO = new MakeOrderDTO();

        OrderDTO orderDTO = orderService.makeOrder(makeOrderDTO);

        Assert.assertNotNull(orderDTO.getAddress());
        Assert.assertNotNull(orderDTO.getPhoneNumber());
    }
}

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
0

Déjame decir algunas palabras

0Comentarios
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

CalienteEtiquetas

Archivo