Gradle DependencySubstitution not working well for test scope

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:

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( {
                            def targetProject = findProject(":${}:${dependency.requested.module}")
                            if (null != targetProject) {
                                dependency.useTarget targetProject

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