Run a class and all dependencies without compiling the whole projects

Answered

Hey guys,

I am in the middle of refactoring a big source code. The whole project will not be compilable for a few months.

I want to do unit tests so I created a few of them.

The class is complicated with a lot of dependencies. Is there any way to compile only the test and its dependencies instead of compiling the whole projects?

I ask this because it is possible to do this in eclipse like one of my colleague has shown me. I don't want to change the IDE I have been used for quite a while but if this is impossible, it is really tempting to move.

I have searched and tried several solutions like using build. dont check error in option and so on. All are not successful.

Thanks.

1
4 comments
Avatar
Permanently deleted user

Hi, 

 

Sadly I have tried the eclipse compiler but all of the tests are failed due to powermock and mockito are unable to create mocks "Mockito can only mock non-private & non-final classes."

Remind that the same codes are actually running perfectly fine on eclipse without a single change after installation

0
Avatar
Permanently deleted user

Hi mrdl2010

You can't run the code that does not compile for obvious reasons. However, you can reduce the compilation scope: in the test run configuration note the module that is chosen there. IDEA will only try to make this module and all modules this one depends on recursively.With javac compiler you will have to make sure everything compiles fine within this scope. If you use eclipse compiler, it may go a bit further and produce classes for non-compilable sources, generating stub methods for those methods that contain errors. So even if technically you can run such code, there is no guarantee that the code will behave the way it should. I would also not rely on tests running against such code, but of course, you mileage may vary.

You can also make sure the code in some certain module is compilable and "manually" compile this module only (see the Build and Rebuild actions in the context menu invoked on the module's node in the Project View). In this case you may also want to change the "before run" action from "Build" to "Build, no error check", so that compilation errors in dependent modules do not prevent running the test.

0
Avatar
Permanently deleted user

mrdl2010 is right, you should be abe to run code that doesn't compile. Eclipse replaces methods that does not compile with an exception. As long as you don't call those methos everything is ok, and if you call it, you will get an exception to console "Method does not compile"

1

Please sign in to leave a comment.