-
Notifications
You must be signed in to change notification settings - Fork 201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Approach PR] [Not ready for review] - Adding support for mocks in test cleanup #107
base: master
Are you sure you want to change the base?
Conversation
@@ -881,6 +899,45 @@ private boolean isCheckedXPFlagName(ExpressionTree tree) { | |||
public Description matchMethod(MethodTree tree, VisitorState state) { | |||
if (disabled) return Description.NO_MATCH; | |||
|
|||
if (!configTestMethodProperties.isEmpty() && tree != null && tree.getBody() != null && tree.getBody().getStatements() != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mkr-plse - This entire logic is very specific and I'm not happy with this approach.
But need your inputs to get this better and generic
@@ -41,5 +41,12 @@ | |||
"linkURL": "<provide_your_url>", | |||
"annotations": [ | |||
"ToggleTesting" | |||
], | |||
"testMethodProperties" : [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will act as the configuration for the test methods that needs to be cleanup. Structure is the same as methodProperties
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just change the flagType for the method. So,
{
"methodName": "when",
"flagType": "mock",
"argumentIndex": 0
}
No separate testMethodProperties
.
List<? extends StatementTree> bt = tree.getBody().getStatements(); | ||
for (StatementTree st : bt) { | ||
if (st != null && st.getKind().equals(Kind.EXPRESSION_STATEMENT)) { | ||
ExpressionStatementTree est = (ExpressionStatementTree) st; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Shouldn't the statement count here be just one? Can we avoid the loop?
- How about calling
evalExpr(st)
? If not,evalExpr(mit)
below and use the result of that. - Before calling the
evalExpr
, callgetXPAPI
and see whether the API isMock
method ? You may also want to updategetXPAPI
to do the necessary processing to check forwhen
and return the appropriate type.
So, the code will be:
API api = getXPAPI(mit) // may be st too.
if(api.equals(API.MOCK)) {
Value value = evalExpr(mit) // may be st too and update evalExpr
if(value != Value.BOT) {
// code starting at line 922.
}
}
This PR is to discuss the possibilities of cleaning up mocks in tests. Approach seems very specific to few use-case and want to discuss approaches here with code.