-
Notifications
You must be signed in to change notification settings - Fork 581
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
tests: unified test names #2553
Comments
If we’re going to come up with a well-defined test name convention, it’d be worth detailing it in the contributing section. |
Let's not take action (like #2552) before we reached the consensus on how to write test names. What do you think is the best way to name/organize test cases? Is there any existing standard for it? |
There is https://github.com/mawrkus/js-unit-testing-guide#design-principles which collects a lot of good ideas in one document (except the "should" in every name which imo is obsolete) which could be a starting point and be adapted for our purposes. |
Examples of my suggestion for a naming convention:
This convention is more or less used in parts of this repo. It aims to be clear and has three ingredients in order:
|
The goal would be not to have test names with "boilerplate", which means no mod name prefix an no function/method prefix. // fs_test.ts
Deno.test("ensureDir()", async (t) => {
await t.step("creates the directory if it doesn't exist", () => ... })
}) The question is what name syntax/casings/tense phrase structure is to use for the name. Do we use Do we use etc. |
Actually, yeah, that's true. Having the module stated isn't needed, but it does help. I think
I don't think this matters all that much. @kt3k and @bartlomieju, what do you guys think? |
I agree with this.
I'm in favor of keeping module names in test names. That might look verbose, but more obvious what are tested, less confusing to newcomers. There are also cases where the test file name and exporting module name don't match. (For example |
If it is easier to read in general, I think it makes much more sense to make
In that case I think the file is not placed right and adding a prefix is a bit "hacky". As I have pointed out here std doesn't have a well defined file structure which needs to be resolved, which automatically would solve this particular issue:
would print |
I feel like we could spend the rest of time debating the test naming convention to use. Yet, it may not be clear which convention is best. Nevertheless, I think it should be kept as simple as possible. To reiterate, this is my idea of ideal test naming:
|
I like that except the submodule name. Imo this should not be part of the test name because the submodule name has nothing to do with the test itself. It seems tedious to add the submodule name to each test, adding unnecessary duplicate information. The test file path is printed along the test name, so ./fs/ensure_dir_test.ts => ensureDir() => creates the directory if it doesn't exist ... ok (31ms) seems explicit enough to me. [functionName]() => [description]
[className.method]() => [description]
[className.property] => [description] = ./fs/ensure_dir_test.ts => ensureDir() => creates the directory if it doesn't exist ... ok (31ms)
./testing/bdd_examples/user_test.ts => User.getAge() => throws at undefined age... ok (19ms)
./testing/bdd_examples/user_test.ts => User.age => returns a number... ok (19ms) |
@kt3k and I now agree that the above should be the test naming convention for the Standard Library. To reiterate, it's as simple as:
To do this, we can do the following:
Does this all sound good @kt3k and @timreichen? |
@iuioiua this sounds great👍 |
Closing this in favour of #3754. |
Is your feature request related to a problem? Please describe.
test names in std use different implementation of test groupings (
[brackets]
,[brackets/with/slashes]
,name with: colon
,name with – dash
) and casings. This was used before nested tests (t.step
) were possible. These naming implementations are inconsistent amongst themselves, "pollute" the actual test name and can be replaced with nested tests or removed altogether.This also will help newcomers in how to write and structure tests.
Describe the solution you'd like
This issue tracks steps to unify tests names in order to have a simple and consistent way of writing tests.
use lower case except mentions of actual classes and/or objects:
Deno.test("do simething", …)
butDeno.test("do something with BigInt", …)
The text was updated successfully, but these errors were encountered: