@Disabled
annotation can be used without providing any reason but its always good to provide a reason why this perticular test case has been disabled, or issue tracker id for better understanding.
package com.example.junit5.sujan;
public class AppleCalculator {
public int addApple(int apple1, int apple2) {
return apple1 + apple2;
}
public int subApple(int apple1, int apple2) {
return apple1 * apple2;
}
}
package com.example.junit5.sujan;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
class AppleCalculatorTest {
@Test
void addAppleTest() {
AppleCalculator appleCalculator = new AppleCalculator();
assertEquals(2, appleCalculator.addApple(1, 1), "1 apple + 1 apple is 2 apple");
}
@Test
@Disabled ("subApple method is returning wrong output, hence disabling it.")
void subAppleTest() {
AppleCalculator appleCalculator = new AppleCalculator();
assertEquals(1, appleCalculator.subApple(2, 1), "2 apple - 1 apple is 1 apple");
}
}
plugins {
id 'java'
}
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
testImplementation('org.junit.jupiter:junit-jupiter:5.6.2')
}
If required we can disabled entire test class as well.
package com.example.junit5.sujan;
public class AppleCalculator {
public int addApple(int apple1, int apple2) {
return apple1 + apple2;
}
public int subApple(int apple1, int apple2) {
return apple1 * apple2;
}
}
package com.example.junit5.sujan;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
@Disabled ("we don't need to run AppleCalculatorTest now, hence disabling it.")
class AppleCalculatorTest {
@Test
void addAppleTest() {
AppleCalculator appleCalculator = new AppleCalculator();
assertEquals(2, appleCalculator.addApple(1, 1), "1 apple + 1 apple is 2 apple");
}
@Test
void subAppleTest() {
AppleCalculator appleCalculator = new AppleCalculator();
assertEquals(1, appleCalculator.subApple(2, 1), "2 apple - 1 apple is 1 apple");
}
}
plugins {
id 'java'
}
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
testImplementation('org.junit.jupiter:junit-jupiter:5.6.2')
}