diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/AfterSuite.java b/src/AfterSuite.java new file mode 100644 index 0000000..33f15e2 --- /dev/null +++ b/src/AfterSuite.java @@ -0,0 +1,9 @@ +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 AfterSuite { +} diff --git a/src/BeforeSuite.java b/src/BeforeSuite.java new file mode 100644 index 0000000..6b8ca43 --- /dev/null +++ b/src/BeforeSuite.java @@ -0,0 +1,9 @@ +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 BeforeSuite { +} diff --git a/src/Main.java b/src/Main.java index 6054a64..7518b71 100644 --- a/src/Main.java +++ b/src/Main.java @@ -1,5 +1,5 @@ public class Main { public static void main(String[] args) { - + StartTest.start(MainTest.class); } } diff --git a/src/MainTest.java b/src/MainTest.java new file mode 100644 index 0000000..948f9ff --- /dev/null +++ b/src/MainTest.java @@ -0,0 +1,34 @@ +public class MainTest { + + @BeforeSuite + public static void test2(){ + System.out.println("test 2 before suite"); + } + + @Test + public static void test8(){ + System.out.println("test8"); + } + + @Test + public static void test1(){ + System.out.println("test1"); + } + + @Test(priority = 2) + public static void test3(){ + System.out.println("test3"); + } + + @Test(priority = 7) + public static void test4(){ + System.out.println("test4"); + } + + @AfterSuite + public static void test5(){ + System.out.println("test5 aftersuite"); + } + + +} diff --git a/src/StartTest.java b/src/StartTest.java new file mode 100644 index 0000000..908bc87 --- /dev/null +++ b/src/StartTest.java @@ -0,0 +1,50 @@ +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; + +public class StartTest { + + public static void start(Class c){ + List methods = new ArrayList<>(); + Method[] classMethods = c.getDeclaredMethods(); + + for (Method classMethod : classMethods) { + if (classMethod.isAnnotationPresent(Test.class)){ + methods.add(classMethod); + } + } + + methods.sort(Comparator.comparingInt((Method i)-> i.getAnnotation(Test.class).priority()).reversed()); + + for (Method classMethod : classMethods) { + if (classMethod.isAnnotationPresent(BeforeSuite.class)){ + if (methods.size()>0&& methods.get(0).isAnnotationPresent(BeforeSuite.class)){ + throw new RuntimeException("@BeforeSuite annotation method>1"); + } + methods.add(0,classMethod); + } + } + + for (Method classMethod : classMethods) { + if (classMethod.isAnnotationPresent(AfterSuite.class)){ + if (methods.size()>0&& methods.get(methods.size()-1).isAnnotationPresent(AfterSuite.class)){ + throw new RuntimeException("@AfterSuite annotation method>1"); + } + methods.add(0,classMethod); + } + } + + for (Method classMethod : classMethods) { + try{ + classMethod.invoke(null); + }catch (IllegalAccessException e){ + e.printStackTrace(); + }catch (InvocationTargetException e){ + e.printStackTrace(); + } + } + + } +} diff --git a/src/Test.java b/src/Test.java new file mode 100644 index 0000000..fbea11c --- /dev/null +++ b/src/Test.java @@ -0,0 +1,10 @@ +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 Test { + int priority() default 5; +}