Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically generate classes based on src folder for test in maven

I'm new to unit testing.

I have a existing maven based project, now my management has asked me to create unit test for all the classes.

So is there any way to automatically generate test classes based on my src package structure.

What I mean is rather than manually replicating the package structure is it possible to automatically generate Test classes.

For instance, if I have com.company.HelloWorld in src folder can it automatically generate com.company.HelloWorldTest in test folder.

Note: actually I do not want the code to be generated automatically just wanted the package structure and test classes to be created within which I can write my own code.

like image 583
ImCoder Avatar asked Dec 05 '25 09:12

ImCoder


1 Answers

I do not know a way to create unit tests automatically. Actually it is almost impossible. Unit test is a class, i.e. code that is typically written by human.

You want to create templates for unit tests. But if you do this automatically they will be empty and there is no way then to prevent you from running empty test cases and be happy that all tests succeed.

So, taking in consideration that you have a tiny project (45 classes) I'd recommend you to create your tests manually. You can however use Eclipse plugin that helps you to create empty test case in correct package.

like image 101
AlexR Avatar answered Dec 07 '25 22:12

AlexR



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!