1 von 6 Zweigen fehlt das Problem mit JacocoJava

Java-Forum
Anonymous
 1 von 6 Zweigen fehlt das Problem mit Jacoco

Post by Anonymous »

Ich stecke in einer Situation fest, in der ich das Problem von 6 Zweigen nicht beheben kann. Unten ist der kleine Code, den ich versucht habe, < /p>
zu produzieren

Code: Select all

package org.example;

public class Testing {

public static final String ONE = "1";

public static boolean condition(String x, boolean y, String z) {
return "ABC".equalsIgnoreCase(x)
&& (y  || ONE.equals(z));
}
}
< /code>
Testfall: < /p>
package org.example;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.Test;

class BranchCoverageTest {

@Test
public void testCondition_xIsABC_yTrue_zNotEqualOne() {
// Testing the case where the first branch is true, but the second branch is false
// "ABC".equalsIgnoreCase("ABC") is true, but (true || "1".equals("1")) is true
assertTrue(Testing.condition("ABC", true, "1"));
}

@Test
public void testCondition_xIsNotABC_yFalse_zEqualsOne() {
// Testing the case where the first branch is false, but the second branch is true
// "ABC".equalsIgnoreCase("DEF") is false, but (false || "1".equals("1")) is true
assertFalse(Testing.condition("DEF", false, "1"));
}

@Test
public void testCondition_xIsNotABC_yFalse_zNotEqualOne() {
// Testing the case where both branches are false
// "ABC".equalsIgnoreCase("DEF") is false, and (false || "1".equals("XYZ")) is false
assertFalse(Testing.condition("DEF", false, "XYZ"));
}

@Test
public void testCondition_xIsABC_yFalse_zNotEqualOne() {
// Testing the case where the first branch is true, but the second branch is false
// "ABC".equalsIgnoreCase("ABC") is true, and (false || "1".equals("XYZ")) is false
assertFalse(Testing.condition("ABC", false, "XYZ"));
}
}

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post