Home > Net >  SpringBoot - Create empty test class for demo
SpringBoot - Create empty test class for demo

Time:09-29

How can I create a empty test class that if mvn test is run it should return Tests run: 0, Failures: 0, Errors: 0, Skipped: 0? Right now without any tests mvn reports no tests to run. I'm working on a demo jenkins pipeline and the script expects all projects to return Tests run: 0 or more.

[INFO] --- maven-surefire-plugin:2.4.2:test (default-test) @ demo-web ---
[INFO] No tests to run.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.535 s
[INFO] Finished at: 2021-09-27T09:04:22Z
[INFO] ------------------------------------------------------------------------
[Pipeline] script

enter image description here

I tried to create a test class but it returns 1 test result. I want zero test results.

BanksMvcControllerTest.java

package com.WebDemo.Controller;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.web.WebAppConfiguration;

import com.webDemo.WebApplication;

import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.context.SpringBootTest;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = WebApplication.class)
@WebAppConfiguration
public class BanksMvcControllerTest {

    @Test
    public void contextLoads() {
    }
}

CodePudding user response:

You could probably annotate the test with @Ignore (for JUnit 4) or @Disabled (for JUnit 5)

CodePudding user response:

Can you try the below code
@Ignore
@Test
public void contextLoads() {
}

Or
@Ignore
public class BanksMvcControllerTest
  • Related