The testCompile configuration to which the JUnit dependency is added is created by some plugin.
If you for example apply the java, groovy or kotlin plugin, this configuration will be present and you can add dependencies to it. If you remove all the plugins that would have added that configuration, you get the mentioned error.