Skip to content

Commit

Permalink
add test demonstrating a rule shared between projects
Browse files Browse the repository at this point in the history
run the following command
> ./gradlew :archunit-example:example-junit4:test --tests "*.ServiceRulesTest" -P example
Inspect the test result file at
> archunit-example/example-junit4/build/reports/tests/test/index.html
You will find a duplicated report for one of the projects, and the failure of the other project is lost.

Issue: TNG#452

Signed-off-by: Christian Semrau <[email protected]>
  • Loading branch information
csemrau committed Oct 19, 2020
1 parent 8fdb631 commit cc7161d
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.tngtech.archunit.exampletest.junit4.platform;

import com.tngtech.archunit.example.layers.MyService;
import com.tngtech.archunit.junit.ArchTest;
import com.tngtech.archunit.lang.ArchRule;

import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes;

/**
* Shared rule, to be referenced in tests of "projectA" and "projectB".
*/
public class ServiceRules {
@ArchTest
public static ArchRule services_should_be_prefixed =
classes()
.that().resideInAPackage("..service..")
.and().areAnnotatedWith(MyService.class)
.should().haveSimpleNameStartingWith("Service");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.tngtech.archunit.exampletest.junit4.projectA;

import com.tngtech.archunit.exampletest.junit4.Example;
import com.tngtech.archunit.exampletest.junit4.platform.ServiceRules;
import com.tngtech.archunit.junit.AnalyzeClasses;
import com.tngtech.archunit.junit.ArchRules;
import com.tngtech.archunit.junit.ArchTest;
import com.tngtech.archunit.junit.ArchUnitRunner;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;

/**
* Runs the shared rules for "projectA" only.
*/
@Category(Example.class)
@RunWith(ArchUnitRunner.class)
@AnalyzeClasses(packages = "com.tngtech.archunit.example.projectA")
public class ServiceRulesTest {
@ArchTest
private final ArchRules service_rules = ArchRules.in(ServiceRules.class);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.tngtech.archunit.exampletest.junit4.projectB;

import com.tngtech.archunit.exampletest.junit4.Example;
import com.tngtech.archunit.exampletest.junit4.platform.ServiceRules;
import com.tngtech.archunit.junit.AnalyzeClasses;
import com.tngtech.archunit.junit.ArchRules;
import com.tngtech.archunit.junit.ArchTest;
import com.tngtech.archunit.junit.ArchUnitRunner;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;

/**
* Runs the shared rules for "projectB" only.
*/
@Category(Example.class)
@RunWith(ArchUnitRunner.class)
@AnalyzeClasses(packages = "com.tngtech.archunit.example.projectB")
public class ServiceRulesTest {
@ArchTest
private final ArchRules service_rules = ArchRules.in(ServiceRules.class);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.tngtech.archunit.example.projectA.service;

import com.tngtech.archunit.example.layers.MyService;

/**
* For Demo purposes only.
*/
@MyService
public class MyServiceA {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.tngtech.archunit.example.projectB.service;

import com.tngtech.archunit.example.layers.MyService;

/**
* For Demo purposes only.
*/
@MyService
public class MyServiceB {
}

0 comments on commit cc7161d

Please sign in to comment.