1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-06-06 18:30:52 +00:00

Merge pull request #1552 from The-Lum/PatchBranch

test: improve [unit] testing, add new test dependencies, add a [possible] logger plugin to gradle, add doc
This commit is contained in:
PlantUML 2023-10-03 14:15:27 +02:00 committed by GitHub
commit 21b9b0bd6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 209 additions and 0 deletions

View File

@ -13,6 +13,7 @@ plugins {
java
`maven-publish`
signing
// id("com.adarshr.test-logger") version "3.2.0"
}
group = "net.sourceforge.plantuml"
@ -28,9 +29,14 @@ java {
dependencies {
compileOnly("org.apache.ant:ant:1.10.13")
testImplementation("io.github.glytching:junit-extensions:2.6.0")
testImplementation("org.assertj:assertj-core:3.24.2")
testImplementation("org.junit.jupiter:junit-jupiter:5.9.2")
testImplementation("org.mockito:mockito-core:4.+")
testImplementation("org.mockito:mockito-junit-jupiter:4.+")
testImplementation("org.scilab.forge:jlatexmath:1.0.7")
"pdfRuntimeOnly"("org.apache.xmlgraphics:fop:2.8")
"pdfRuntimeOnly"("org.apache.xmlgraphics:batik-all:1.16")
}

81
docs/TESTING.md Normal file
View File

@ -0,0 +1,81 @@
# Testing PlantUML
## Prerequisites
See the [Building page](../BUILDING.md) and especilay the paragraph [Building PlantUML with Gradle](../BUILDING.md#building-plantuml-with-gradle).
## Running Tests
### Run all tests, for all licences
To run the tests included with the project, use the following command:
```sh
gradle test
```
### Run a specific test, for only one licence
Comment those lines on [`settings.gradle.kts`](../settings.gradle.kts):
https://github.com/plantuml/plantuml/blob/a327d636a7fcc7f05a88b796a2838da16e2ba3e3/settings.gradle.kts#L12-L16
Then you can run a specific test _(e.g. the `aTestClass` Class)_:
```sh
gradle test --tests aTestClass
```
## Contributing
After successfully building and testing the project, you are ready to start [contributing](../CONTRIBUTING.md) to PlantUML!
If you have any changes to contribute, please submit a pull request through the [PlantUML GitHub repository](https://github.com/plantuml/plantuml).
## Test Directory Architecture
- [test/](../test)
- [com/plantuml/wasm](../test/com/plantuml/wasm)
- [net/sourceforge/plantuml](../test/net/sourceforge/plantuml)
- [nonreg](../test/nonreg)
```mermaid
%%{ init : { "flowchart" : { "curve" : "stepBefore" }}}%%
graph LR
T["test/"]
T -->|"Unit Test\n(of src/com/plantuml/api/cheerpj)"| W["com/plantuml/wasm"]
T -->|"Unit Test\n(of src/net/sourceforge/plantuml)"| U["net/sourceforge/plantuml"]
T -->|"Non-regression Test"| N[nonreg]
```
## Additional Resources
### Gradle
- site: [Gradle](https://gradle.org)
- doc: [Gradle User Guide](https://docs.gradle.org/current/userguide/userguide.html)
- src: [:octocat:Gradle](https://github.com/gradle/gradle)
### Gradle Plugins
- site: [Gradle Plugins Search](https://plugins.gradle.org)
- A "gradle test logger plugin"
- src: [:octocat:radarsh/gradle-test-logger-plugin](https://github.com/radarsh/gradle-test-logger-plugin)
### JUnit
- site: [JUnit5](https://junit.org/junit5/)
- doc: [JUnit User Guide](https://junit.org/junit5/docs/current/user-guide/)
- src: [:octocat:JUnit-team](https://github.com/junit-team)
### JUnit extensions
- doc: [JUnit extensions](https://junit.org/junit5/docs/current/user-guide/#extensions)
- The "Glytching" JUnit extensions
- doc: [Glytching JUnit extensions](https://glytching.github.io/junit-extensions/)
- doc: [`randomBeans` doc](https://glytching.github.io/junit-extensions/randomBeans)
- src: [:octocat:glytching/junit-extensions](https://github.com/glytching/junit-extensions)
### AssertJ
- doc: [AssertJ](https://assertj.github.io/doc/)
- src: [:octocat:AssertJ](https://github.com/assertj/assertj)
### Mockito
- site: [Mockito](https://site.mockito.org)
- doc: [Mockito doc.](https://javadoc.io/doc/org.mockito/mockito-core/latest/org/mockito/Mockito.html)
- src: [:octocat:Mockito](https://github.com/mockito/mockito)

View File

@ -0,0 +1,122 @@
package net.sourceforge.plantuml.utils;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import io.github.glytching.junit.extension.random.Random;
import io.github.glytching.junit.extension.random.RandomBeansExtension;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.Extensions;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
@Extensions({
@ExtendWith(MockitoExtension.class),
@ExtendWith(RandomBeansExtension.class)
})
class LineLocationImplTest {
@Mock
private LineLocation parent;
@Mock
private LineLocation parent2;
@Random
private String desc;
@Random
private String desc2;
@Test
void ctorDestArgMustNotBeNull() {
assertDoesNotThrow(() -> new LineLocationImpl(desc, null));
assertThrows(NullPointerException.class, () -> new LineLocationImpl(null, null));
}
@Test
void initialPositionIsNegativeOne() {
LineLocation loc = new LineLocationImpl(desc, null);
assertEquals(-1, loc.getPosition());
}
@Test
void parentSameAsProvided() {
LineLocation loc = new LineLocationImpl(desc, parent);
assertSame(parent, loc.getParent());
}
@Test
void descriptionSameAsProvided() {
LineLocation loc = new LineLocationImpl(desc, parent);
assertEquals(desc, loc.getDescription());
}
@Test
void toStringIsAConcatenationofDescAndPosition() {
LineLocationImpl loc = new LineLocationImpl(desc, parent);
assertEquals(desc + " : -1", loc.toString());
assertEquals(desc + " : 0", loc.oneLineRead().toString());
}
@Test
void oneLineReadMovesToNextLine() {
LineLocationImpl loc = new LineLocationImpl(desc, parent);
for (int i = 1; i < 5; ++i) {
LineLocationImpl next = loc.oneLineRead();
assertEquals(desc, next.getDescription());
assertSame(parent, next.getParent());
assertEquals(-1 + i, next.getPosition());
loc = next;
}
}
@Test
void comparisonStandardLibraryAlwaysDifferent() {
LineLocationImpl loc1 = new LineLocationImpl(desc, parent);
LineLocationImpl loc2 = new LineLocationImpl("<" + desc2, parent);
assertEquals(1, loc1.compareTo(loc2));
assertEquals(-1, loc2.compareTo(loc1));
}
@ParameterizedTest
@ValueSource(strings = {"", "<"})
void comparisonDisregardsDescription(String prefix) {
LineLocationImpl loc1 = new LineLocationImpl(prefix + desc, parent);
LineLocationImpl loc2 = new LineLocationImpl(prefix + desc2, parent);
assertEquals(0, loc1.compareTo(loc2));
assertEquals(0, loc2.compareTo(loc1));
}
@ParameterizedTest
@ValueSource(strings = {"", "<"})
void comparisonDisregardsParent(String prefix) {
LineLocationImpl loc1 = new LineLocationImpl(prefix + desc, parent);
LineLocationImpl loc2 = new LineLocationImpl(prefix + desc, parent2);
assertEquals(0, loc1.compareTo(loc2));
assertEquals(0, loc2.compareTo(loc1));
}
@ParameterizedTest
@ValueSource(strings = {"", "<"})
void comparisonLooksAtPositionOnly(String prefix) {
LineLocationImpl loc1 = new LineLocationImpl(prefix + desc, parent);
LineLocationImpl loc2 = loc1.oneLineRead();
LineLocationImpl loc3 = loc2.oneLineRead();
assertEquals(-1, loc1.compareTo(loc2));
assertEquals(1, loc2.compareTo(loc1));
assertEquals(-2, loc1.compareTo(loc3));
assertEquals(2, loc3.compareTo(loc1));
}
}