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

initial draft for unit tests for software architecture using ArchUnit #569

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

akinwale-habibullah
Copy link

Please read through the writing guide before submitting a pull request and go through this checklist (at least for your first article).

Feel free to raise the pull request even if the checklist hasn't been worked through, yet, to take advantage of the online preview that is generated for each pull request (see "deploy/netlify" under "Show all checks" in your pull request). But please only flag it to be reviewed by your editor after going through the checklist.

Review

  • you have reviewed the text a day after finishing it (you'd be surprised how many errors you can avoid by just getting some distance to what you've written)

Content

  • the article explains why and not only how
  • (half-)sentences that express a meaningful idea that is understandable by itself own are bold to allow quick scanning of the text
  • the text has been checked with Grammarly (the free tier is enough)

Text

  • the text is conversational ("we" instead of "you", easy language)
  • there are no "walls of text" (short sentences, short paragraphs with a single idea)
  • the text is inclusive ("the developers" and "they" instead of "the developer" and "he/she")
  • the text uses active voice instead of passive voice
  • names are spelled consistently throughout the article (correct uppercase / lowercase)
  • file names and variables are highlighted as code

Structure

  • the article has a short intro before the first headline
  • by reading the table of contents (TOC) alone, I get a sense of the "story" of the article (check the TOC in the preview after raising the PR or by starting the blog locally on your machine)
  • if using sub-headlines, there's at least two sub-headlines below a main-headline
  • headlines are consistent throughout the article (same level of abstraction, same style - if one headline starts with a verb in imperative form, the other headlines on the same level should probably, too)

Code Examples

  • code examples are introduced with a ":" and explained below the code example
  • code examples are formatted to avoid horizontal scrolling (manual line breaks and 2-spaces indentation)


ArchUnit is a free, simple and extensible library for checking the architecture of your Java code using any plain Java unit test framework.

ArchUnit has different layers: the Core layer, the Lang layer, and the Library layer.
Copy link
Member

Choose a reason for hiding this comment

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

As a user of ArchUnit, this is not the most important fact about ArchUnit. I don't really care about the "layering" of ArchUnit itself. I care about learning which use cases I can use it for and how to use it. Can you rewrite the "What is ArchUnit" section to start with a complete example and then explaining it? Potentially after this, you can explain about the layering.

.resideInAPackage("..service..")
.should()
.onlyBeAccessed()
.byAnyPackage("..controller..", "..service..");
Copy link
Member

Choose a reason for hiding this comment

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

Please combine all three code examples in this section to a single one. Start the section with a sentence about what ArchUnit is, then show the code example, then explain the code example. That's the best way to introduce ArchUnit to the readers.


## What to check

What should we check in architectural tests in the first place? The typical checks we can do with ArchUnit are class dependencies and package dependency checks to enforce dependency rules in a class or between classes in different packages. Package dependency check is commonly used in Spring Modulith applications to check that classes do not depend on a class in another bounded context.
Copy link
Member

Choose a reason for hiding this comment

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

You're assuming the reader knows what Moduliths is ... please don't do that.

In general, this section is rather weak. As a reader, I don't really learn from this section what I can do with ArchUnit. I would like to see a couple subsections in this section, each explaining a certain use case in a sentence or two.


## Getting started with ArchUnit

Let us create a Spring Boot application. Although the example in this article is a bit contrived, it can help us understand how to use ArchUnit in a typical web application with different layers.
Copy link
Member

Choose a reason for hiding this comment

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

The part of this article about creating a new Spring Boot application takes up over 50% of the article. This article is about ArchUnit and not Spring Boot.

I think we can remove the whole start.spring.io stuff and just show some very simple example classes that have all the features you need for the use cases you're showing. Instead of the Spring Boot stuff, feel free to add more than the two example ArchUnit use cases.

I also suggest to put the code examples directly into the use case sections. I.e. In the section "Test to check repositories are only accessed by services", start with showing two very simple service and repository classes, and then show the ArchUnit test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants