JUnit测试用例出错。 “未找到测试运行程序'JUnit'的测试

时间:2020-02-20 20:28:13

标签: angular junit

JUnit测试用例出错。 “未找到测试运行程序'JUnit'的测试。 在pom中,它寻找依赖项和mvn install失败。因此,如何在运行时未选择在package.json包中添加依赖项jasmine


it('should open justification comment window, () => {
        component.onClickPassActionButton();
        expect(component.inputJustificationPopUpRef.isOpen).toBeTruthy();
    });

    it('should fire validation error for the textbox of justification comment window, () => {
        let action: LASUXModalAction = {};
        component.comment = "";
        component.onModalInputJustificationAction(action);
        expect(component.displayErrorForJustification).toBeTruthy();
    });

    it('should close justification comment window, () => {
        let action: LASUXModalAction = {};
        component.comment = "";
        component.onModalInputJustificationAction(action);
        expect(component.displayErrorForJustification).toBeFalsy();
        expect(component.comment.length<=0).toBeTruthy();
    });

    it('should open justification confirmation window, () => {
        let action: LASUXModalAction = {};
        component.comment = "test dummy";
        component.onModalInputJustificationAction(action);
        expect(component.displayErrorForJustification).toBeFalsy();
        expect(component.comment.length<=0).toBeFalsy();
        expect(component.confirmJustificationPopUpRef.isOpen).toBeTruthy();
    });

    it('should submit comment of justification comment window', inject(
        [DecisionPipelineService],
        (service: DecisionPipelineService) => {
            spyOn(service,
                'submitJustificationApproval').and.returnValue(throwError(new Error('error')));
                let action: LASUXModalAction = {};
                component.comment = "test dummy";
                component.onModalConfirmJustificationAction(action);
                expect(component.internalRequestDetails.status.toLowerCase()).toEqual("approved");
                expect(component.internalRequestDetails.fontColor).toEqual(hexColor.GREEN);
        }
    ));

    it('should close justification confirmation window & open justification comment window, () => {
        let action: LASUXModalAction = {};
        component.comment = "test dummy";
        component.onModalConfirmJustificationAction(action);
        expect(component.confirmJustificationPopUpRef.isOpen).toBeFalsy();
        expect(component.inputJustificationPopUpRef.isOpen).toBeTruthy();
    });

1 个答案:

答案 0 :(得分:0)

您需要在pom文件中包含spring boot starter测试。

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
   <version>2.1.4.RELEASE</version>
    <scope>test</scope>
</dependency>

此范围测试用于指示在应用程序的标准运行时不需要依赖关系,而仅用于测试目的。

Spring boot starter测试包括以下依赖项:

  1. JUnit 4:用于对Java应用程序进行单元测试的事实上的标准。
  2. Spring测试和Spring Boot测试:实用程序和集成测试 对Spring Boot应用程序的支持。
  3. AssertJ:流畅的断言库。
  4. Hamcrest:匹配对象库(也称为 约束或谓词)。
  5. Mockito:一个Java模拟框架。
  6. JSONassert:JSON的断言库。 JsonPath:JSON的XPath

添加了弹簧启动启动器的pom。

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.mycompany.app</groupId>
  <artifactId>my-app</artifactId>
  <version>1.0-SNAPSHOT</version>

  <properties>
     <java.version>1.8</java.version>
  </properties>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.2.RELEASE</version>
</parent>

  <dependencies>
   <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
        <version>2.1.4.RELEASE</version>
    </dependency>


    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <version>2.1.4.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
        <version>2.1.4.RELEASE</version>
    </dependency>



    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
        <version>2.1.4.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <version>2.1.4.RELEASE</version>
    </dependency>

   <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
   <version>2.1.4.RELEASE</version>
    <scope>test</scope>
 </dependency>

  </dependencies>
</project>