-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import org.junit.jupiter.api.*; | ||
|
||
public class mathTest { | ||
@BeforeEach | ||
public void init(){ | ||
System.out.println("init..."); | ||
} | ||
|
||
@AfterEach | ||
public void close(){ | ||
System.out.println("close..."); | ||
} | ||
|
||
|
||
@Test | ||
public void testMath(){ | ||
math test = new math(); | ||
test.Myprint(); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package medium.Check; | ||
|
||
public class Calculator { | ||
// @Check | ||
public int sum(int a, int b){ | ||
return (a + b); | ||
} | ||
@Check | ||
public void p(){ | ||
System.out.println("NoAnnotation"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package medium.Check; | ||
|
||
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 Check { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package medium.Check; | ||
|
||
import java.io.BufferedWriter; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
|
||
public class TestCheck { | ||
public static void main(String[] args) throws IOException { | ||
Calculator c = new Calculator(); | ||
Class cls = c.getClass(); | ||
Method[] methods = cls.getMethods(); | ||
|
||
int num = 0; | ||
BufferedWriter bw = new BufferedWriter(new FileWriter("bug.txt")); | ||
|
||
for(Method method : methods){ | ||
if (method.isAnnotationPresent(Check.class)){ | ||
try { | ||
method.invoke(c); | ||
} catch (Exception e) { | ||
//捕获异常 | ||
num ++; | ||
bw.write(method.getName() + "方法出异常了"); | ||
bw.newLine(); | ||
bw.write("异常的名称:" + e.getClass().getSimpleName()); | ||
bw.newLine(); | ||
bw.write("异常原因:" + e.getCause().getMessage()); | ||
bw.newLine(); | ||
bw.write("------------------------------------"); | ||
bw.newLine(); | ||
} | ||
} | ||
} | ||
bw.write("本次测试共有" + num + "次异常"); | ||
bw.flush(); | ||
bw.close(); | ||
} | ||
|
||
|
||
} |