Created a full stack app archtest don't seem to work

I generated a full stack app using the Create a new Vaadin app: configure views and theme selecting the check box full stack react and hilla.

The @ArchTest don’t seem to do anything or work. I tried mvn test and it says it sees the file, but with the bad rules I put in there it should not have passed. Doesn’t seem to work.

However integration test does seem to work or at least run. Using mvn -Pintegration-test integration-test.

Not sure how these tests are supposed to run, run them, and there is no docs.

[INFO] Running com.hidden.app.ArchitectureTest
23:27:56.084 [main] INFO com.tngtech.archunit.core.PluginLoader – Detected Java version 22.0.2
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.853 s – in com.hidden.app.ArchitectureTest
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

Hello! I’ll have a look at the test it’s currently generating. Can you post the rules you put in there?

-Petter-

Thanks. I didn’t add any, just trying to run what it came with out of the box. Oh I edited the ones there, munging package names to see if a fail would occur.

Here is a bad example I also tried.

  @ArchTest
  public static final ArchRule some_test = classes().that().resideInAPackage("con.hidden").should().bePrivate();

I added a @Test and those seem to run.

  @Test
  public void some_architecture_rule() {
    JavaClasses importedClasses = new ClassFileImporter().importPackages("com.hidden");
    ArchRule rule = classes().that().resideInAPackage("com.hidden").should().notBePrivate();

    rule.check(importedClasses);
  }

Thanks. I just downloaded a fresh skeleton with Hilla views and ran some tests:

In the Task class, I added a method that took TaskService as a parameter:

    public void foo(TaskService service) {
    }

This resulted in the domain_model_should_not_depend_on_application_services failing.

Next, I created a new hidden package in the base package and put a public class in it. I then added the following rule to the test, which failed:

@ArchTest
public static final ArchRule hidden_classes = classes().that().resideInAPackage(BASE_PACKAGE + ".hidden..").should().notBePublic();

I then changed the public class to package private and now the test passed.

Can you please repeat these tests in your project and see if the results are the same?

import com.hidden.app.taskmanagement.service.TaskService;

@Entity
@Table(name = "task")
public class Task extends AbstractEntity<Long> {
  public void foo(TaskService service) {
  }

Tried first and did not fail.

Then I added the second with

package com.hidden.app.hidden;

public class Hidden {
}
  @ArchTest
  public static final ArchRule hidden_classes = classes().that().resideInAPackage(BASE_PACKAGE + "..hidden..").should()
      .notBePublic();

Run with .\mvn.cmd clean test

[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.hidden.app.ArchitectureTest
09:50:17.981 [main] INFO com.tngtech.archunit.core.PluginLoader -- Detected Java version 21.0.2
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.169 s -- in com.hidden.app.ArchitectureTest
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS

I would recommend to refactore this class. I’ve heard of multiple people in the past that those static archunit sometimes just don’t execute - IDE, Maven, Junit and so on… something just doesn’t line up perfectly in the universe. Using separate normal test method should work 100% of the time and should still be fast enough

2 Likes

Interesting. When I run the test in the IDE, it works as expected. When I run it via Maven, I get the same result as you. I’ll dig into this.

It does look like Maven is not running the @ArchTest rules, whereas IntelliJ IDEA does. As @knoobie suggested, I’m refactoring them to be ordinary @Test methods. Will notify you here when the changes are published to start.vaadin.com.

1 Like

The refactored architecture tests are now live. @jpywtora please try to download a new skeleton and see if they work better now.

-Petter-

I will check it out asap, should be tomorrow, California. I am also a Neovim user along with the cli on Windows.

Nice refactor and validated that for me all tests pass now from the CLI for the generated started. Thank you

1 Like