Kotlin / dokka

API documentation engine for Kotlin
https://kotl.in/dokka
Apache License 2.0
3.44k stars 408 forks source link

Integration tests refactoring #2925

Open IgnatBeresnev opened 1 year ago

IgnatBeresnev commented 1 year ago

Dokka's integration tests run Dokka on real projects using various versions of Gradle, Kotlin and Android, and make sure there are no abnormalities, all links are present, everything is resolved and is able to be built, etc. This is extremely useful, and the same behaviour should be preserved.

Additionally, the integration tests are used for generating and publishing live demos of documentation to S3, which is very useful for reviewing UI/UX changes. This feature should be preserved as well.


However, the way that the tests are set up now is not optimal, and it's causing problems in various places:

  1. The tests cannot be cached by Gradle as they define incorrect inputs/outputs. More information here.
  2. The tests are lumped together under the same task, so it's more difficult to have unique configuration for a project (more information here).
  3. External test projects, such as kotlinx.coroutines, are imported as git submodules. This is just annoying to maintain and update, and not obvious to someone encountering it for the first time. Maybe these projects could be added as dependencies, more information here
  4. (to be continued)

The outlined problems should be researched and addressed if possible.

aSemy commented 1 year ago

Improving the integration tests is also connected to improving Dokka's Gradle build files #2703, since the integration tests break project isolation to publish Dokka to Maven Local

https://github.com/Kotlin/dokka/blob/1acfb6051637c10034b09b3c15c562472fad68b3/build-logic/src/main/kotlin/org/jetbrains/taskUtils.kt#L6-L14

I'm working on a Gradle Plugin for solving this problem, (though it's still awaiting approval in the Plugin Portal). I actually manually tested it using Dokka! It required a significant amount of changes though, so I'll make a PR as a demonstration, but I wanted to break it up into smaller pieces.

aSemy commented 1 year ago

There was a discussion on Gradle Slack this week and https://github.com/gradle/exemplar was recommended for running integration tests. Although I find it pretty tough to understand how to use it, I think it would be worth investigating.

IgnatBeresnev commented 11 months ago

Grooming notes

Introduction

We have some integration tests already, but they've proven to be somewhat difficult to maintain, to extend, and they have some problems in their core that are getting in the way of other related things. These tests were a good start, but since their inception we've figured out additional use cases, figured out what works and what doesn't, and what's useful or would be nice to have in general.

The hypothesis is that it'll be much easier and faster to start completely from scratch and re-implement integration (e2e) tests based on the specific desires / requirements and our experience, than to try to salvage the existing tests. Moreover, starting from scratch should also be safer, as it'll allow us to have a seamless transition from the old tests to the new, without worrying that the old (primary) tests accidentally break after refactoring.

Types of tests

There are two types of integration / end-to-end tests:

They could have the same setup (like now), but because they are useful in different ways - it might be easier to separate them, where each type has its own requirements.

Artificial project tests

Examples of issues it helps find:

Notes:

Arbitrary user projects

Examples of issues it helps find:

Notes:

Pain points

Some pain points of the existing tests:

General notes / requirements

Things to keep in mind while designing the solution:

Nice to have

IgnatBeresnev commented 11 months ago

First iteration

It makes sense to start with something smaller and approachable, and then build on top of it.

The first iteration can focus on: