import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface CustomAnnotation {
String value() default "This is a custom annotation";
}
public class MyClass {
@CustomAnnotation("Custom Annotation Example")
public void myMethod() {
// Your method implementation here
}
}
JUnit单元测试
所在的类必须是public,非抽象的,包含唯一的无参构造器
@Test标记的方法本身必须是public,非抽象的,非静态的,void无返回值,()无参数的
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class MyMath {
public int add(int a, int b) {
return a + b;
}
@Test
public void testAdd() {
MyMath math = new MyMath();
int result = math.add(3, 4);
assertEquals(7, result);
}
}