jeffoffutt / muJava

Mutation system for Java programs, including OO mutation operators.
Apache License 2.0
66 stars 43 forks source link

How to run test files in package structure? #21

Open synchi opened 4 years ago

synchi commented 4 years ago

Hi,

Generating the mutants works perfectly well when my source code is under a package structure, as instructed by MuJava documentation. But, only test files in the root testset directory are visible to MuJava - it will not run the tests under a package structure. When I flatten all the test files out of their directories, MuJava still won't work because of the package definitions mismatching the files. I've now tried refactoring the entire project to be flat (fixing things such as nested imports which require a package), as flattening only the tests and refactoring everything to work turned out too tedious. I hope it will now succeed - but I have many more projects to set up with MuJava, and I feel like this is not the right way to go...

Is there any way to make MuJava (MuScript) run the test files in a package structure, just like the source code?

If this is not available, could you point me to where MuJava's code should be modified please?

Many thanks, Sara

winonecheng commented 4 years ago

In my opinion, mutation tool is not suitable for large project. Do mutant in code snippet or little program.

synchi commented 4 years ago

Thanks for your reply @winonecheng. I would like to use MuJava for my thesis research using a variety of standard Java projects. MuJava provides the flexibility I need, therefore I hope this feature to be a possibility. Do you have any suggestions on how to configure or implement this for MuJava?

winonecheng commented 4 years ago

could u show your project structure?

synchi commented 4 years ago

@winonecheng For example: https://github.com/apache/commons-lang Just a standard src/main/java/org/etc structure, where the java files under /java (so starting with org) are placed in MuJava's src folder. I've compiled the project and placed the entirety of the class files, in their original package structure, from the target folder (instead of the src folder, and starting from org) into MuJava's classes folder. This perfectly allows for generating mutants. Then ideally, I'd like to place the entirety of subdirectories in target/test-classes/org into MuJava's testset, but MuJava won't run the tests under the subdirectory structure.

winonecheng commented 4 years ago

Ok, I see. Because MuJava cant run multiple test files in the same time (one command), you have to merge all test cases into single file and refactor the project. It takes a lot of work. If only MuJava supported CLI, you could write a simple script to run through your test files.

Since you can generate the mutants, its not hard to use a script to run all junit test cases and all mutants. Hope it will be helpful to you 👍

synchi commented 4 years ago

@winonecheng Exactly, I attempted flattening and refactoring the project, and got it running (kind of, it exited with an exception). But due to the nature of my research, this is not going to be a feasible approach. I do use MuScript, MuJava's CLI version. https://cs.gmu.edu/~offutt/mujava/muscript/ I was indeed considering finding a way to automate the process myself, I'll think about that :)