Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
X
xm-sportstest
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
xiamai-test
xm-sportstest
Commits
31c93767
Commit
31c93767
authored
Dec 25, 2024
by
DuJunLi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
解决TestNG 中多 class 乱序问题
parent
07fe3508
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
73 additions
and
7 deletions
+73
-7
module/polar/整个模块.xml
+3
-1
src/main/java/com/xiaomai/cases/polar/schedule/group/TestDelCurrentAndSubsequentGroupSchedule.java
+4
-6
src/main/java/com/xiaomai/client/RePrioritizingListener.java
+66
-0
No files found.
module/polar/整个模块.xml
View file @
31c93767
<?xml
version="1.0" encoding="UTF-8"?>
<?xml
version="1.0" encoding="UTF-8"?>
...
...
@@ -11,5 +11,6 @@
<listener
class-name=
"com.xiaomai.client.RetryListener"
/>
<listener
class-name=
"com.xiaomai.client.TestListener"
/>
<listener
class-name=
"com.xiaomai.client.ExtentTestNGIReporterListener"
/>
<listener
class-name=
"com.xiaomai.client.RePrioritizingListener"
></listener>
<!-- 解决TestNG 中多 class 乱序问题 -->
</listeners>
</suite>
\ No newline at end of file
src/main/java/com/xiaomai/cases/polar/schedule/group/TestDelCurrentAndSubsequentGroupSchedule.java
View file @
31c93767
...
...
@@ -55,17 +55,15 @@ public class TestDelCurrentAndSubsequentGroupSchedule extends UniversalDataSched
.
filter
(
e
->
e
.
getString
(
"ruleId"
).
equals
(
groupRuldId
)).
count
();
Assert
.
assertTrue
(
countB
==
0
,
"删除当前及后续课次后,课表中后端返回数据有问题,目前还能发现数据"
);
}
}
@Test
(
description
=
"删除此case创建的日程"
,
priority
=
1
)
public
void
delData
()
{
if
(!
StringUtils
.
isEmpty
(
groupRuldId
))
{
//获取到的日程ID不为空时,则逐个删除相关日程
//删除对应日程
groupScheduleTools
.
delGroupRuleSchedule
(
groupRuldId
,
true
);
}
}
}
}
...
...
src/main/java/com/xiaomai/client/RePrioritizingListener.java
0 → 100644
View file @
31c93767
package
com
.
xiaomai
.
client
;
/**
* 解决testng 中的 method 乱序问题解决
* 当一个 class 中多个 testmethod 的时候 而且 testmethod 通过 priority 设置顺序时, testng.xml 有多个这样的 class 可能会出现乱序问题,因为 testng 一开始会加载所有的 annotation , 所以在 testng 看来 classA.testmethod.priority=1 与 classB.testmethod.priority=1 是同样的优先级。
* @author adu
* data 2024/12/25 09:42
*/
import
java.lang.reflect.Constructor
;
import
java.lang.reflect.Method
;
import
java.util.HashMap
;
import
org.testng.IAnnotationTransformer
;
import
org.testng.Reporter
;
import
org.testng.annotations.ITestAnnotation
;
//Listener to fix TestNG Interleaving issue. I had to re-write this as the original example I had did not allow for priority to be manually set on a test level.
public
class
RePrioritizingListener
implements
IAnnotationTransformer
{
HashMap
<
Object
,
Integer
>
priorityMap
=
new
HashMap
<
Object
,
Integer
>();
Integer
class_priorityCounter
=
10000
;
// The length of the final priority assigned to each method.
Integer
max_testpriorityLength
=
4
;
@Override
public
void
transform
(
ITestAnnotation
annotation
,
Class
testClass
,
Constructor
testConstructor
,
Method
testMethod
)
{
// class of the test method.
Class
<?>
declaringClass
=
testMethod
.
getDeclaringClass
();
// Current priority of the test assigned at the test method.
Integer
test_priority
=
annotation
.
getPriority
();
// Current class priority.
Integer
current_ClassPriority
=
priorityMap
.
get
(
declaringClass
);
if
(
current_ClassPriority
==
null
)
{
current_ClassPriority
=
class_priorityCounter
++;
priorityMap
.
put
(
declaringClass
,
current_ClassPriority
);
}
String
concatenatedPriority
=
test_priority
.
toString
();
// Adds 0's to start of this number.
while
(
concatenatedPriority
.
length
()
<
max_testpriorityLength
)
{
concatenatedPriority
=
"0"
+
concatenatedPriority
;
}
// Concatenates our class counter to the test level priority (example
// for test with a priority of 1: 1000100001; same test class with a
// priority of 2: 1000100002; next class with a priority of 1. 1000200001)
concatenatedPriority
=
current_ClassPriority
.
toString
()
+
concatenatedPriority
;
//Sets the new priority to the test method.
annotation
.
setPriority
(
Integer
.
parseInt
(
concatenatedPriority
));
String
printText
=
testMethod
.
getName
()
+
" Priority = "
+
concatenatedPriority
;
Reporter
.
log
(
printText
);
System
.
out
.
println
(
printText
);
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment