为什么 JUnit 不起作用,为什么我会收到错误消息?

我第一次尝试使用 JUnit 来测试我的代码。我使用了使用相同代码的学习剪辑,一切正常,但对我不起作用!这是我得到的错误的一部分:


创建名为“org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$EnableWebMvcConfiguration”的bean时出错:通过构造函数的bean实例化失败


ReservationControllerTest.java :


package com.frankmoley.landon.web.application;


import com.frankmoley.landon.business.domain.RoomReservation;

import com.frankmoley.landon.business.service.ReservationService;

import org.junit.Test;

import org.junit.runner.RunWith;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;

import org.springframework.boot.test.mock.mockito.MockBean;

import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import org.springframework.test.web.servlet.MockMvc;


import java.text.DateFormat;

import java.text.SimpleDateFormat;

import java.util.ArrayList;

import java.util.Date;

import java.util.List;


import static org.mockito.BDDMockito.given;

import static org.hamcrest.CoreMatchers.containsString;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;

import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;

import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;


@RunWith(SpringJUnit4ClassRunner.class)

@WebMvcTest(ReservationController.class)

public class ReservationControllerTest {


@MockBean

private ReservationService reservationService;

@Autowired

private MockMvc mockMvc;


    }

}


青春有我
浏览 62回答 2
2回答

料青山看我应如是

如果您使用的 Java 版本高于 8,则可能需要将此依赖项添加到您的 POM:<dependency>&nbsp; &nbsp; <groupId>javax.xml.bind</groupId>&nbsp; &nbsp; <artifactId>jaxb-api</artifactId>&nbsp; &nbsp; <version>2.2.11</version></dependency><dependency>&nbsp; &nbsp; <groupId>com.sun.xml.bind</groupId>&nbsp; &nbsp; <artifactId>jaxb-core</artifactId>&nbsp; &nbsp; <version>2.2.11</version></dependency><dependency>&nbsp; &nbsp; <groupId>com.sun.xml.bind</groupId>&nbsp; &nbsp; <artifactId>jaxb-impl</artifactId>&nbsp; &nbsp; <version>2.2.11</version></dependency><dependency>&nbsp; &nbsp; <groupId>javax.activation</groupId>&nbsp; &nbsp; <artifactId>activation</artifactId>&nbsp; &nbsp; <version>1.1.1</version></dependency>因为其中一些类被删除了。

慕妹3242003

将 junit 依赖项添加到您的 pom.xml<dependency>&nbsp; &nbsp; <groupId>junit</groupId>&nbsp; &nbsp; <artifactId>junit</artifactId>&nbsp; &nbsp; <version>4.12</version>&nbsp; &nbsp; <scope>test</scope></dependency>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java