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

Add ability to parse test classes #16

Closed
sunigos opened this issue Sep 19, 2018 · 21 comments
Closed

Add ability to parse test classes #16

sunigos opened this issue Sep 19, 2018 · 21 comments

Comments

@sunigos
Copy link

sunigos commented Sep 19, 2018

I work a lot with test automation and most of the code is located in src/test/java directory (maven structure).
I want to create a class diagram for my testing project (it's pretty big and have more than 300 classes), but I can't use uml-reverse-mapper because it ignores classes in src/test/java and looks only in src/main/java
It would be cool to add some attrubute to look for package not in the /main, but in the /test.

@iluwatar
Copy link
Owner

@sunigos great improvement suggestion. Definitely worth looking into.

@sivasubramanim
Copy link

@iluwatar : Can I work on this enhancement?

@iluwatar
Copy link
Owner

Sure @sivasubramanim go ahead

@sivasubramanim
Copy link

sivasubramanim commented Sep 18, 2019

We can enable the ability to parse test classes with a simple change to the existing urm-maven project ->DomainMapperMojo class -> getClasspathUrls() method
project.getCompileClasspathElements() needs to be modified to project.getTestClasspathElements()
getTestClasspathElements()(includes urls of outputdirectory and TestOutputDirectory) is a super set of getCompileClasspathElements()

After this change, getClasspathUrls() method will return the target/classes url and target/test-classes url also. I tested the changes on a local project which has code in src/test/java and src/main/java and I am able to successfully generate the diagram.

We should also modify the maven plugin parameter
from:
"< execution >
< phase >process-classes</ phase >
< goals > < goal >map</ goal >
</ goals >
</ execution > "
to:
< execution>
< phase>process-test-classes</ phase>
< goals>
< goal>map</ goal>
</ goals>
</ execution>"

With these 2 changes, we can provide the ability to parse test classes for the urm-maven project.

@iluwatar : Can you please let me know your thoughts on this?

@iluwatar
Copy link
Owner

Thanks for looking into this. I think it would be good to have parameters for this. Whether the user wants to generate the diagrams from the src/main/java (default) or src/test/java or both. This way we are able to support all possible combinations the users can ask.

@sivasubramanim
Copy link

Agreed @iluwatar . I will create two parameters namely
includeMainDirectory(default true)
includeTestDirectory(default false)

sivasubramanim added a commit to sivasubramanim/uml-reverse-mapper that referenced this issue Sep 27, 2019
Add ability to parse test classes
@sivasubramanim
Copy link

@iluwatar : I created a pull request with the changes for this enhancement. Please review it.
We should also be changing the README.md file to handle the changes in the < phase></ phase> if the user wants to include test directory. Please let me know if you want me to handle those changes also.

@iluwatar
Copy link
Owner

@sivasubramanim looks good so far. Please add also the documentation to README.md. In addition it would be great to make symmetrical changes to urm-core project although we can create another issue for that if you prefer.

@sivasubramanim
Copy link

sivasubramanim commented Oct 1, 2019

Thank you for reviewing my changes. I will make the necessary changes to the README.md file also.
Currently urm-core project takes archive file(jar) as the input and generates the class diagram.Test classes will not be packaged together with the compile classes. However we can package test classes separately as an archive in maven. Class diagrams can be generated for both the compile classes archive and test classes archive. I locally tested this and it works.

@iluwatar I feel the existing urm-core project can handle this scenario. Please let me know your thoughts.

@iluwatar
Copy link
Owner

iluwatar commented Oct 1, 2019

Good news if urm-core already handles this scenario. If you have example steps how to do this I would be interested. May be worth mentioning in the README.md as well.

@sivasubramanim
Copy link

@iluwatar I will create a sample project and share the same with you on this regards in couple of days.

@iluwatar
Copy link
Owner

iluwatar commented Oct 7, 2019

Many thanks @sivasubramanim. I'm looking forward to it.

@sivasubramanim
Copy link

sivasubramanim commented Oct 9, 2019

@iluwatar I created two sample projects at https://github.com/sivasubramanim/UrmTester

  1. Test Framework type of project which does not have any src/main classes .
  2. Project having both main and test classes - I have used your java-design-patterns/singleton project for this
    I have created a repo temporarily to hold these projects. We can delete this repo after the review.

Steps to Create Class Diagram using urm-core for Project which has only test classes:

  1. Execute mvn clean install -Pdev to generate FAT test jar named MyWebApp-0.0.2-SNAPSHOT-fat-tests.jar
  2. I have configured the POM with maven-assembly-plugin to generate the test jar . Please refer the output directory where i have placed the already compiled JAR (https://github.com/sivasubramanim/UrmTester/tree/master/Java-Selenium-TestNG-Automation-Framework/output)
  3. Copy the urm-core-1.4.4.jar and MyWebApp-0.0.2-SNAPSHOT-fat-tests.jar to a common folder.
  4. execute the below command:
    java -cp MyWebApp-0.0.2-SNAPSHOT-fat-tests.jar;urm-core-1.4.4.jar de.markusmo3.urm.DomainMapperCli -p com.autoframework.suite -f testonlydiagram.puml
  5. This should generate the diagram. You can refer the already generated diagram at https://github.com/sivasubramanim/UrmTester/blob/master/Java-Selenium-TestNG-Automation-Framework/output/testonlydiagram.puml

Steps to Create Class Diagram using urm-core for Project which has both main and test classes as two seperate diagrams:

  1. Execute mvn clean install -Ptest to generate separate test-only jar named singleton-1.22.0-SNAPSHOT-tests.jar and src/main jar named singleton-1.22.0-SNAPSHOT.jar
  2. I have configured the POM with maven-assembly-plugin to generate the test-only jar . Please refer the output directory where i have placed the already compiled JAR (https://github.com/sivasubramanim/UrmTester/tree/master/singleton/outputs)
  3. Copy the urm-core-1.4.4.jar, singleton-1.22.0-SNAPSHOT.jar and singleton-1.22.0-SNAPSHOT-tests.jar to a common folder.
  4. execute the below command for generating src/main JAR diagram:
    java -cp singleton-1.22.0-SNAPSHOT.jar;urm-core-1.4.4.jar de.markusmo3.urm.DomainMapperCli -p com.iluwatar.singleton -f maindiagram.puml
  5. execute the below command for generating src/test JAR diagram:
    java -cp singleton-1.22.0-SNAPSHOT-tests.jar;urm-core-1.4.4.jar de.markusmo3.urm.DomainMapperCli -p com.iluwatar.singleton -f testdiagram.puml
  6. This should generate the diagrams. You can refer the already generated diagram at https://github.com/sivasubramanim/UrmTester/blob/master/singleton/outputs/maindiagram.puml
    https://github.com/sivasubramanim/UrmTester/blob/master/singleton/outputs/testdiagram.puml

Steps to Create Class Diagram using urm-core for Project which has both main and test classes in one combined diagram:

  1. Execute mvn clean install -Pdepmaintest to generate fat JAR having both src/main and src/test classes named singleton-1.22.0-SNAPSHOT-fat-tests.jar
  2. I have configured the POM with maven-assembly-plugin to generate the fat jar . Please refer the output directory where i have placed the already compiled JAR (https://github.com/sivasubramanim/UrmTester/tree/master/singleton/outputs)
  3. Copy the urm-core-1.4.4.jar and singleton-1.22.0-SNAPSHOT-fat-tests.jar to a common folder.
  4. execute the below command for generating diagram:
    java -cp singleton-1.22.0-SNAPSHOT-fat-tests.jar;urm-core-1.4.4.jar de.markusmo3.urm.DomainMapperCli -p com.iluwatar.singleton -f maintestdiagram.puml
  5. This should generate the diagram. You can refer the already generated diagram at https://github.com/sivasubramanim/UrmTester/blob/master/singleton/outputs/maintestdiagram.puml

As part of this sample i tried to cover all the possible use cases:

  1. Only Main Diagram
  2. Only Test Diagram
  3. Main and Test Diagram as two separate diagrams
  4. Main and test as a combined single diagram

Please let me know your thoughts on this?

@sivasubramanim
Copy link

Since we are using reflections for this class diagrams the expectation is that we need to have all the referenced/import classes in the JAR(JAR with dependencies). If we can build the JAR with dependencies urm-core will be able to generate the diagram. This applies to both src/main or src/test classes.

@iluwatar
Copy link
Owner

iluwatar commented Oct 10, 2019

Steps to Create Class Diagram using urm-core for Project which has only test classes

Yes, I succeeded in the steps. I was just wondering why the diagram contains also WebDriver and some other related classes.

image

@iluwatar
Copy link
Owner

Thanks for comprehensive testing @sivasubramanim I can confirm that everything with urm-core works as you wrote. If you can expand the README.md a bit I think we are ready to merge this.

@sivasubramanim
Copy link

sivasubramanim commented Oct 10, 2019

@iluwatar The additional classes which you see are identified by the fieldscanner as edges of type static inner classes. Attaching a debug session screenshot on the same:
Capture_edges

As far as classes we got only the 4 classes but the remaining came up as part of the fieldscanner.

@sivasubramanim
Copy link

sivasubramanim commented Oct 10, 2019

I will update the README.md related to the changes we did to the urm-maven project. Can you please let me know if you are looking for any changes to the documentation related to urm-core project.

@iluwatar
Copy link
Owner

Just updating the documentation related to the changes made in this pull request is enough.

sivasubramanim pushed a commit to sivasubramanim/uml-reverse-mapper that referenced this issue Oct 14, 2019
Add ability to parse test classes

Updating README.md file
@sivasubramanim
Copy link

@iluwatar Updated the README.md document.

iluwatar added a commit that referenced this issue Oct 15, 2019
@iluwatar
Copy link
Owner

Thank you @sivasubramanim for implementing this requested feature 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants