“classe de test maven” Réponses codées

classe de test maven

mvn install -Dmaven.test.skip=true

# or

mvn install -DskipTests

# If -Dmaven.test.skip=true (or simply -Dmaven.test.skip) is specified, 
# the test-jars aren't built, and any module that relies on them will 
# fail its build.

# In contrast, when you use -DskipTests, Maven does not run the tests, 
# but it does compile them and build the test-jar, making it available 
# for the subsequent modules.
DevPedrada

classe de test maven

private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
private final ByteArrayOutputStream errContent = new ByteArrayOutputStream();
private final PrintStream originalOut = System.out;
private final PrintStream originalErr = System.err;

@Before
public void setUpStreams() {
    System.setOut(new PrintStream(outContent));
    System.setErr(new PrintStream(errContent));
}

@After
public void restoreStreams() {
    System.setOut(originalOut);
    System.setErr(originalErr);
}

sample test cases:

@Test
public void out() {
    System.out.print("hello");
    assertEquals("hello", outContent.toString());
}

@Test
public void err() {
    System.err.print("hello again");
    assertEquals("hello again", errContent.toString());
}
DevPedrada

Réponses similaires à “classe de test maven”

Questions similaires à “classe de test maven”

Plus de réponses similaires à “classe de test maven” dans Shell/Bash

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code