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

End to End Testing (Java) #551

Merged
merged 35 commits into from
Aug 8, 2022
Merged

Conversation

SuyDesignz
Copy link
Contributor

@SuyDesignz SuyDesignz commented Aug 1, 2022

First version of the endToEndTest strategy for jplag.java

The first endToEnd tests are included, as well as the required auxiliary classes and the plagiarisms created from the literature for each test.

The test cases each contain two delivery classes, which consists of the original file "SortAlgo.java" as well as a plagiarized file.
The plagiarisms were created and added to the project as described in the associated issue.

Test-Workflow

  1. Check if the resources needed for the tests exist.
@Before
	public void setUp() {
		assertTrue(Constant.BASE_PATH_TO_JAVA_RESOURCES_SORTALGO.toFile().exists(), "Could not find base directory!");
		try {
			assertTrue(Constant.BASE_PATH_TO_JAVA_RESULT_JSON.toFile().exists(),
					"Could not find java result xml at " + Constant.BASE_PATH_TO_JAVA_RESULT_JSON + "!");

		} catch (Exception e) {
			assertTrue(false, e.getMessage());
		}
	}
  1. The required plagiarism names are passed to the JPlagTestSuiteHelper as an array. It searches for the resources and copies them into a temporary directory which will be checked later by the JPLag api.
String[] testClassNames = new String[] { "SortAlgo.java", "SortAlgo1.java" };

try {
   var testSuiteHelper = new JPlagTestSuiteHelper(testClassNames);
   List<String> submissionTestPaths = new ArrayList<String>();
   submissionTestPaths.add(testSuiteHelper.getFolderPath());
  1. The temporary directory is now examined with the help of the JPlag api. Here it is important to call the method "close();" of the JPLagTestSuiteHelper, since this deletes and releases the copied data again.
   JPlagOptions options = new JPlagOptions(submissionTestPaths, new ArrayList<String>(), LanguageOption.JAVA);

   JPlag jplag = new JPlag(options);
   JPlagResult result = jplag.run();
   // after close the created directories are deleted
   testSuiteHelper.close();
  1. Now the stored results must be loaded for the test using the ResultComparison object. Here the results are assigned to the names of the calling method.
ResultComparison resultComparison = new ResultComparison(new Object() {
			}.getClass().getEnclosingMethod().getName());
  1. The result of JPLag is compared with the stored results.
   // for the fine-granular testing strategy, the result object contains only one
   // comparison.
   for (JPlagComparison jPlagComparison : result.getAllComparisons()) {
      System.out.println("Comparison of the stored values and the current equality values");
      assertEquals(resultComparison.getSimilarity(), jPlagComparison.similarity());
   }

TODO

  • Creating tests for saving new results
  • Creating the jsonWriter
  • extend the test cases
  • Extending the comparative values

@tsaglam tsaglam added enhancement Issue/PR that involves features, improvements and other changes minor Minor issue/feature/contribution/change labels Aug 1, 2022
@tsaglam tsaglam added this to the v4.0.0 milestone Aug 1, 2022
@SuyDesignz
Copy link
Contributor Author

SuyDesignz commented Aug 1, 2022

Already in preparation:
I would like to rewrite the testSuieteHelper that it is possible to create the instance in the @before and the individual tests can only pass the names of the plagiarism in a method call. makes for less code and better readability.

Copy link
Member

@dfuchss dfuchss left a comment

Choose a reason for hiding this comment

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

Some initial remarks :)

Copy link
Member

@tsaglam tsaglam left a comment

Choose a reason for hiding this comment

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

Also from me a quick early review.

@SuyDesignz SuyDesignz marked this pull request as ready for review August 1, 2022 21:40
@tsaglam tsaglam requested review from a team August 2, 2022 06:49
@SuyDesignz SuyDesignz requested a review from dfuchss August 3, 2022 12:37
Copy link
Member

@dfuchss dfuchss left a comment

Choose a reason for hiding this comment

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

Some more comments. Also merge master to your branch :)

@dfuchss
Copy link
Member

dfuchss commented Aug 3, 2022

Also add it to the module structure. (to the default profile; not to the deployment profile)

@SuyDesignz
Copy link
Contributor Author

First of all, thanks for the quick help! I have now adjusted the pom's. Regarding the name for the test cases. Is it wanted that the endToEnd tests run every time? Especially I still implement the "test case" which puts the cached results into the json. This should not run with the build in any case.

@dfuchss
Copy link
Member

dfuchss commented Aug 6, 2022

Is it wanted that the endToEnd tests run every time?

I think the E2E test have to run at any build. Just ensure that the state of your committed E2E test is runnable. You can change the tests later if needed.

Especially I still implement the "test case" which puts the cached results into the json. This should not run with the build in any case.

If this is not a real test. Simply mark it with @Disabled this prevent the execution during build

@SuyDesignz
Copy link
Contributor Author

SuyDesignz commented Aug 6, 2022

Did I forget something when checking the JavaResult.json file or why can't it be found? Locally it works but in the build test run it cannot be found. However, the previously required resource Directoire is found.

Click to show!

Build error

Error:  Errors: 
Error:    JavaEndToEndTest.setUp:37 » FileNotFound src/test/resources/results/javaResult.json (No such file or directory)

Checking the paths and files in JavaEndToEndTest.java

    @BeforeAll
    public void setUp() throws IOException {
        jplagTestSuiteHelper = new JPlagTestSuiteHelper(LanguageOption.JAVA);
        assertTrue(Constant.BASE_PATH_TO_JAVA_RESOURCES_SORTALGO.toFile().exists(), "Could not find base directory!");
        assertTrue(Constant.BASE_PATH_TO_JAVA_RESULT_JSON.toFile().isFile(), "Could not find java result json!");
    }

Specified paths in Constant.java

    /**
     * Base path to the created plagiarism and the main file located in the project resources.
     */
    public static final Path BASE_PATH_TO_JAVA_RESOURCES_SORTALGO = Path.of("src", "test", "resources", "java", "sortAlgo");
    /**
     * Base path to the saved results of the previous tests in a *.json file
     */
    public static final Path BASE_PATH_TO_JAVA_RESULT_JSON = Path.of("src", "test", "resources", "results", "javaResult.json");

@dfuchss
Copy link
Member

dfuchss commented Aug 6, 2022

Linux FS is case sensitive. Build is fixed now.

@dfuchss dfuchss changed the title Feature/end to end testing End to End Testing Aug 6, 2022
@dfuchss dfuchss changed the title End to End Testing End to End Testing (Java) Aug 6, 2022
@SuyDesignz
Copy link
Contributor Author

Is there anything else missing from the PR? This already includes the basic tests, resources and helper functions. The additional functions for the EndToEndTests are intended for the next PR but are already in progress.

@tsaglam
Copy link
Member

tsaglam commented Aug 7, 2022

Is there anything else missing from the PR? This already includes the basic tests, resources, and helper functions. The additional functions for the EndToEndTests are intended for the next PR but are already in progress.

Both @dfuchss and I will check your changes, and then we will either accept or make some further comments. Probably not today, though.

Copy link
Member

@dfuchss dfuchss left a comment

Choose a reason for hiding this comment

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

I've marked some locations that I would not log. Please wait for @tsaglam opinion here, as these suggestions are just a personal opinion of me. I would suggest to either delete them or to use logger.debug() . Otherwise, the output will contain too much (from my point of view)

But that's a very minor remark. Therefore, I approve now.

@SuyDesignz
Copy link
Contributor Author

I definitely agree with you about the logger. The outputs could also be sufficient purely for the debug version.

@tsaglam
Copy link
Member

tsaglam commented Aug 8, 2022

I would suggest to either delete them or to use logger.debug()

Both are fine for me, but logger.info is definitely not! @SuyDesignz choose either one of the suggestions by @dfuchss.

Copy link
Member

@tsaglam tsaglam left a comment

Choose a reason for hiding this comment

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

Just one small thing...

@SuyDesignz
Copy link
Contributor Author

Since I only created the PR as a draft, should I create it the PR now?

@tsaglam
Copy link
Member

tsaglam commented Aug 8, 2022

Since I only created the PR as a draft, should I create it the PR now?

This already is a non-draft PR. What is an argument against merging this one?

@SuyDesignz
Copy link
Contributor Author

I had it set up as a draft and was not aware that it had already been changed. I will create a readMe file for the RP, but then everything would be ready so far.

@sonarcloud
Copy link

sonarcloud bot commented Aug 8, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

84.2% 84.2% Coverage
0.0% 0.0% Duplication

@tsaglam tsaglam merged commit 19d39f2 into jplag:master Aug 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Issue/PR that involves features, improvements and other changes minor Minor issue/feature/contribution/change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants