ArchUnit icon indicating copy to clipboard operation
ArchUnit copied to clipboard

Any plans for Intellij Plugin Development

Open nagkumar opened this issue 3 years ago • 4 comments

I was presenting ArchUnit in Bangalore JUG today, and one of the attendees did give a great idea. Reporting the same for considering in future roadmaps

Is there a possibility of building the IDE plugin around #ArchUnit Rules, so that the rules violations can be caught during the code writing in IDE itself rather than the current way of building and running test cases to know the voilations?

nagkumar avatar Aug 13 '22 07:08 nagkumar

One advantage of ArchUnit is that its tests can be executed just like any other unit test.

For instance, if you use plain JUnit @Tests (like in ArchUnit-Examples's example-plain), you can directly execute them individually from IntelliJ:

image

If you use ArchUnit's JUnit support for @ArchTests, i.e. the ArchUnitRunner for JUnit 4 or the archunit-junit5-engine for JUnit 5, IntelliJ supports running the entire test class file:

image

hankem avatar Aug 13 '22 11:08 hankem

This depends on what you want. As @hankem pointed out, it's easy to run the tests from the IDE like any ordinary unit test. This will compile the classes and then the bytecode can be imported. To have this e.g. as a live plugin within the IDE we would likely need to do a massive overhaul to allow filling the model from a different source. E.g. IntelliJ's PSI model. There once was an issue, but I never found the time for such a massive overhaul, since it would really mean designing new interfaces for users to plug into the import and also change the accessibility of the model completely (as it e.g. at the moment is not possible to create new JavaClasses for the users of ArchUnit and I think this is i.g. a good thing) -> #116 Otherwise, maybe it would also be possible to always compile the classes on the fly and import them, but I'm not sure how feasible that is :thinking: Given also, that ArchUnit at the moment allows no update of the class graph once it's created and again, changing that would likely be a highly non-trivial thing :thinking:

codecholeric avatar Aug 20 '22 08:08 codecholeric

Agreed. I wish to give some more info on deeper IDE integration.

I can see the potential of archunit with proper libraries more than unit tests, such as helping developers learn faster the framework they are coding in.

With IDE deeper integration few advantages to support developers are

  1. Create ArchUnit 'different architecture' template test code by default. If we say onion architecture etc For e.g when the spring project is created, also create respective arch unit source tests cases that are applicable to that framework
  2. When Analysing the code, show deviations in IDE as in this image

image

With my current understanding of ArchUnit, I see it as Architecture as CODE (hence wish every framework provide these arch unit test library default, including Spring and in cloud space Amzaon Well-Architected framework etc), hence at least 50% to 70% of the architecture rules can be standardized and enforced as usual in JUnit test cases depending on the project type itself. This way learning curve of the new developers to that framework etc.. would drastically increase. I am sure this way, they can get used to unit tests too easily.

However, I do understand the bandwidth needed and the level of effort needed to make this happen.

Thank you for your efforts in making archunit.

nagkumar avatar Aug 20 '22 10:08 nagkumar

I completely agree, that it would be great to have ArchRules within your IDE as you type with direct feedback :slightly_smiling_face: I'm just afraid that it is really a big endeavor to get there with some real challenges to overcome. Even just thinking about the fact that I might want to evaluate rules on the fly that are part of my sources of my project. I.e. the plugin that checks the progress of me writing code depends on the compiled output of other code within the same project. I wouldn't know if IntelliJ e.g. would even allow that. And what if you would edit the rules themselves? But configured the rules you're editing to be checked against the code you're editing at the moment :zany_face: Just some things that come to mind, why it would at least be challenging (maybe impossible) to use the same patterns as for unit tests for a IDE plugin :shrug:

codecholeric avatar Aug 25 '22 16:08 codecholeric