Gradle DependencySubstitution not working well for test scope

Hello,
Environment: Gradle 2.6, multi project build
We use dependency substitution feature, to substitute module dependency with project dependency if project is checked out.
Main idea is the following:
rootDir:
–projectA
–projectB

projectB dependes on projectA modules. If projectA is checked out, we’ll use it as dependency, if not we’ll use nexus deployed library.

Our test code of projectB depends on the test code of projectA. So in project B module we’ll have something like this: testCompile ‘projectA:module1:1.0.12345:tests’, which will resolve properly if no projectA is checked out. It will also work properly if we define project dependency directly like this: testCompile project(’:projectA:module1’).sourceSets.test.output and projectA is checked out.

However, our module dependency substitution will not work dynamically.

configurations {
    all { conf ->
        resolutionStrategy {
            dependencySubstitution {
                all { DependencySubstitution dependency ->
                    if (dependency.requested instanceof ModuleComponentSelector) {
                        if (topProjects.contains(dependency.requested.group)) {
                            def targetProject = findProject(":${dependency.requested.group}:${dependency.requested.module}")
                            if (null != targetProject) {
                                dependency.useTarget targetProject
                            }
                        }
                    }
                }
            }
        }
    }
}

topProjects is a map defined outside of the scope with top level directories.