question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow different naming conventions for tests

See original GitHub issue

In tests, I like to have very specific method names that are human readable.

For example:

fun `With input X, the output should be Y`()

However, this is not valid in Android apps.

As such, it would be nice if I could specify a different configuration for the tests in my project.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
MyDogTomcommented, Jun 7, 2017

You can achieve this by having two different Gradle tasks with different filters and config values. Let’s assume that all your tests are placed in directories with test suffix (eg. src/test, src/sharedTest, src/androidTest etc)

Here is example of configuration for all files except tests

    task detektCheck(type: JavaExec) {
        main = "io.gitlab.arturbosch.detekt.cli.Main"
        classpath = configurations.detekt
        def input = "$project.projectDir.absolutePath"
        def config = "$project.projectDir/../config/detekt/detekt_configuration_main.yml"
        def filters = ".*src/\\w*[Tt]est/.*"
        def rulesets = ""
        def params = ['-p', input, '-c', config, '-f', filters, '-r', rulesets]
        args(params)
    }

Configuration for files in “test” directories

    task detektCheckTests(type: JavaExec) {
        main = "io.gitlab.arturbosch.detekt.cli.Main"
        classpath = configurations.detekt
        def input = "$project.projectDir.absolutePath"
        def config = "$project.projectDir/../config/detekt/detekt_configuration_tests.yml"
        def filters = ".*src/(?!(\\w*[Tt]est))"
        def rulesets = ""
        def params = ['-p', input, '-c', config, '-f', filters, '-r', rulesets]
        args(params)
    }

As I said, difference in filters and config fields.

Disadvantage of this approach is that you have to duplicate your configuration, because mostly it will be identical (except naming configuration)

2reactions
scottkennedycommented, Jun 4, 2017

Yes, this is how I have it set up:

task detektApp(type: JavaExec) {
    main = "io.gitlab.arturbosch.detekt.cli.Main"
    classpath = configurations.detekt
    def input = "$project.projectDir.absolutePath"
    def output = "$project.projectDir.absolutePath/build/reports/detekt/"
    def config = "$project.rootDir/reporters/detekt/detekt.yml"
    def filters = ".*src/test/.*"
    def rulesets = ""
    def params = ['-p', input, '-c', config, '-f', filters, '-r', rulesets, '-o', '-rp', output]
    args(params)
}

task detektTests(type: JavaExec) {
    main = "io.gitlab.arturbosch.detekt.cli.Main"
    classpath = configurations.detekt
    def input = "$project.projectDir.absolutePath"
    def output = "$project.projectDir.absolutePath/build/reports/detekt/"
    def config = "$project.rootDir/reporters/detekt/detekt_tests.yml"
    def filters = ".*src/(?!(test))/.*"
    def rulesets = ""
    def params = ['-p', input, '-c', config, '-f', filters, '-r', rulesets, '-o', '-rp', output]
    args(params)
}

Hmmm I’m thinking I have this backwards now, but you get the idea.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to name your unit tests. 4 test naming conventions
Writing long names is acceptable since test names should show the purpose behind what they're testing.
Read more >
Unit test naming best practices [closed] - Stack Overflow
One test fixture per 'unit' (class of your program). Test fixtures are classes themselves. The test fixture name should be: [name of your...
Read more >
Making Better Unit Tests, Part 2: naming unit tests - Manning
From Unit Testing, Principles, Practices, and Patterns by Vladimir Khorikov. In this article, we'll talk about naming unit tests.
Read more >
7 Popular Strategies: Unit Test Naming Conventions - DZone
The article presents a compiled list of unit tests naming strategy that one could follow for naming their unit tests.
Read more >
How to Choose the Best Unit Test Method Naming Convention
1. UnitOfWork name could be as simple as a method name (if that is the whole unit of work) or more abstract if...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found