0

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() {
    }
}
user630702
  • 2,529
  • 5
  • 35
  • 98
  • afaik you cannot. You either have 1 test that runs or 1 that is ignored. So no you cannot have all the counters set to 0. – M. Deinum Sep 28 '21 at 08:06
  • oh okay. I was expecting something like this from the asnwer https://stackoverflow.com/a/69334020/13410618 – user630702 Sep 28 '21 at 08:10
  • Nope. So either write a test, or skip it, but it will lead to output with a 1 at one place. If there is nothing you get the message you get now (not sure if that is configurable). But why not just put in that single test and it will adhere to the rules of your CI... – M. Deinum Sep 28 '21 at 08:19

2 Answers2

1

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

Sebastiaan van den Broek
  • 5,818
  • 7
  • 40
  • 73
0

Can you try the below code:

@Ignore
@Test
public void contextLoads() {
}

Or:

@Ignore
public class BanksMvcControllerTest
Shaido
  • 27,497
  • 23
  • 70
  • 73