Skip to content
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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sivacoder
Copy link
Contributor

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.

  1. Code not prod ready
  2. Tests not added

@@ -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) {
Copy link
Contributor Author

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" : [
Copy link
Contributor Author

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

Copy link
Contributor

@mkr-plse mkr-plse Oct 29, 2020

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Shouldn't the statement count here be just one? Can we avoid the loop?
  2. How about calling evalExpr(st)? If not, evalExpr(mit) below and use the result of that.
  3. Before calling theevalExpr, call getXPAPI and see whether the API is Mock method ? You may also want to update getXPAPI to do the necessary processing to check for when 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. 
      }
}

@ketkarameya ketkarameya marked this pull request as draft August 7, 2022 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants