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

Order of tests should be optimized for Test Driven Development #702

Closed
mk-mxp opened this issue May 4, 2024 · 1 comment
Closed

Order of tests should be optimized for Test Driven Development #702

mk-mxp opened this issue May 4, 2024 · 1 comment

Comments

@mk-mxp
Copy link
Contributor

mk-mxp commented May 4, 2024

Problem

Exercism states in some places, that the "test first" approach it uses, is like TDD. This does not hold true for the order of tests in problem specifications.

While making over minesweeper I followed TDD to develop the new example solution. There the tests jump from no dimension to both dimensions and come back later to one dimension. This leads to having to write the complete solution early to satisfy a test, without being guided through all the steps towards the final solution. And the tests coming after this early 2-dimensional test then do pass with no new code being written.

Problem specs in general group tests by a theme or a common property. This does not want to be the right order for TDD. It follows different rules.

Also, PHPUnit does not guarantee execution order of tests. Following FIRST principles, order must not matter. But that is not true for the process of TDD, only for using the tests later to prove correctness.

I think it is very advanced TDD knowledge to know which test needs to be passed next. So presenting students with an unordered list of failing tests does not help them to find their way through implementing a solution. At least, the tests should be ordered according to a good path through the TDD journey. It would be even better to always have only one failing test - which is a core property of TDD.

With this in mind, I think PHP track should have:

  • A way to order tests optimized for TDD
  • A way to keep / enforce the order when an exercise is sync'ed to problem specs
  • Optionally a way to present students with only one failing test instead of a wall of failures

Suggested solution

PHPUnit allows dependencies (@depends) between tests. These are not explicitly meant to enforce an execution order, but by definition a test depending on the result of a previous test ensures an execution order for those tests. As a side effect PHPUnit skips tests when the tests fail they depend upon. This technically solves the way how to have the tests ordered and only fail one test at a time.

To know the designed order of tests, we may add a key testOrder to .meta/config.json with an ordered list of UUIDs. This list must be considered by test generators as well as contributors. When it does not exist, we fall back to the order in problem specs.

@mk-mxp
Copy link
Contributor Author

mk-mxp commented Oct 30, 2024

It was agreed upon in the forum, that the order of tests in canonical data should be followed and that the order should be optimized there. Also the grouping was seen as useless for most tracks and was questioned, but there was no agreement to flatten the data.

@mk-mxp mk-mxp closed this as completed Oct 30, 2024
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

No branches or pull requests

1 participant