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

[3.4] Assertion improvements #498

Closed
LeoColman opened this issue Dec 5, 2018 · 11 comments
Closed

[3.4] Assertion improvements #498

LeoColman opened this issue Dec 5, 2018 · 11 comments
Assignees
Labels
enhancement ✨ Suggestions for adding new features or improving existing ones.
Milestone

Comments

@LeoColman
Copy link
Member

LeoColman commented Dec 5, 2018

The module kotlintest-assertions has some room for improvements. There are many matchers/assertions that are deprecated and were moved, and many matchers have no documentation and not enough tests.

Breaking change: Remove deprecated methods

This issue aims to mark as error all deprecated methods, forcing users to change their imports to the new ones. The deprecated methods will be moved to a legacy directory, that will be removed

This will be an issue to current users, but will save new and old users of the following situation:
image
"Which import should I use?"
"Oh, this one is deprecated, then I believe it's the other one"

I've noticed that this happens a lot to new users. The confusion is more of an annoying thing than a big problem, but it's bad for user experience. Marking these deprecations as an Error will provide users a quick way to move to the new versions, and will remove this problem.

Code improvement: All tests, in assertions module itself

Some matchers aren't tested for corner cases. Some also don't have any code coverage. To allow new matchers to be developed, and an improvement to assertion quality assurance, all matchers should be covered by unit tests, guaranteeing their functionality.

To further improve the assertions module, their tests can be moved to its module, and not the global kotlintest-tests module. In the near past, 2 contributors were asked to create tests to their new features, and neither of them knew at first where to place the tests. If possible, moving all tests to be near their test-targets will encourage new contributors to add more tests.

However, I remember @sksamuel commenting that due to module building order, it wouldn't be possible to do this. If it is, it would be better for contributors to understand what to do directly

Documentation improvements: Add KDocs to all matchers

Good documentation in-code will allow users to know what a matcher/assertion does without opening Github and scanning through the documentation there. It improves the user experience and the resilience of matchers, as we'll have the documentation of exactly how it does (our current docs have short sentences. Maybe they're not explicit enough to some users).

Contributing to this

I created the branch feature/assertions-improvements. If you have any contribution related to the above comments, feel free to open a Pull Request to that branch!

@LeoColman LeoColman added this to the 3.3 milestone Dec 5, 2018
@LeoColman
Copy link
Member Author

@sksamuel I know that forcing users to change their packages due to deprecation is very bad, but I don't know if we should keep the deprecated methods.

What do you think about this?

@sksamuel
Copy link
Member

sksamuel commented Dec 5, 2018

I am happy for the deprecated methods to be removed in 3.3

@LeoColman
Copy link
Member Author

And then we do all the changes at once, to avoid users having to change everything everytime

@sksamuel
Copy link
Member

sksamuel commented Dec 5, 2018

Let's not move them all for the sake of it but ones like shouldBe definitely need to be removed now.
And assertion tests can move into the assertions module. It's the core tests (testing the engine itself) that must exist in a separate module.

@LeoColman
Copy link
Member Author

I believe we should remove all the deprecated now, to avoid having to create issues to user in the future again due to deprecation.

My line of thought is "well... If they will have to change imports for this now, it's better to change for the others now than having to change them again in the future"

@sksamuel
Copy link
Member

sksamuel commented Dec 5, 2018

Anything that is deprecated can be removed (unless it was deprecated in 3.2, then it's too early).
Should be one full release cycle where it is deprecated.

@LeoColman
Copy link
Member Author

LeoColman commented Dec 5, 2018 via email

@sksamuel
Copy link
Member

sksamuel commented Dec 5, 2018

Yep.

LeoColman added a commit that referenced this issue Dec 7, 2018
Moves all assertions tests to the assertions module

As part of #498, all tests that test the `kotlintest-assertions` module were moved to it, bringing the tests closer to their targets, and decreasing confusion to future contributors.

An important point to be noted: the root package chosen is `assertions.io.kotlintest`. This was done because putting files in `io.kotlintest` package make them subject to stacktrace cleaning, by the Failures class. The Failures class removes all Kotlintest stacktraces from throwables, so that the user only sees the real problem, and nothing internal. However. as we're using `io.kotlintest` for all the tests, the user stacktraces would be removed (we are the users), and that's not good when a test fails, as no reason would be given.

Fixes a part of #498 - Moves tests closer to their targets
@LeoColman LeoColman added the enhancement ✨ Suggestions for adding new features or improving existing ones. label Dec 8, 2018
@sksamuel
Copy link
Member

sksamuel commented Jan 7, 2019

One enhancement I think would be really nice would be the ability to do soft asserts in a closure:

someObj should {
  matcher1
  matcher2
}

For example

name should {
  haveLength(3)
  beDigitsOnly()
  include("!")
}

Would have to think about how to include not's in there.

An alternative could be

name.shouldHaveLength(3).beDigitsOnly().include("!")

@sksamuel
Copy link
Member

sksamuel commented Jan 7, 2019

Another enhancement I think is to deprecate shouldHave, and just keep should and rename all matchers to work with the consistent "should" verb.

LeoColman added a commit that referenced this issue Jan 10, 2019
Moves all assertions tests to the assertions module

As part of #498, all tests that test the `kotlintest-assertions` module were moved to it, bringing the tests closer to their targets, and decreasing confusion to future contributors.

An important point to be noted: the root package chosen is `assertions.io.kotlintest`. This was done because putting files in `io.kotlintest` package make them subject to stacktrace cleaning, by the Failures class. The Failures class removes all Kotlintest stacktraces from throwables, so that the user only sees the real problem, and nothing internal. However. as we're using `io.kotlintest` for all the tests, the user stacktraces would be removed (we are the users), and that's not good when a test fails, as no reason would be given.

Fixes a part of #498 - Moves tests closer to their targets
@sksamuel sksamuel mentioned this issue Jan 30, 2019
20 tasks
@sksamuel sksamuel modified the milestones: 3.3, 3.4 Feb 5, 2019
@sksamuel sksamuel changed the title [3.3] Assertion improvements [3.4] Assertion improvements Feb 5, 2019
@sksamuel sksamuel mentioned this issue Feb 16, 2019
88 tasks
@LeoColman
Copy link
Member Author

Closing this. It's starting to get old, and not exactly related to changes we're doing now.

If th need rise in the future, I'll reopen this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement ✨ Suggestions for adding new features or improving existing ones.
Projects
None yet
Development

No branches or pull requests

2 participants