"No tests were found" happens at random
已回答
I was happily working on my project just now, when I attempted to right-click the root of my project structure, and "Run 'All Tests'", when I got "No tests were found". I had done just the same thing 10 minutes prior, so I can't imagine why this is happening.
In addition, none of my scratches works either. Almost all imports now says "does not exist". I have attempted "Invalidate caches and restart" (several times) to no avail. What am I doing wrong?
This is my build.gradle:
plugins {
id 'org.springframework.boot' version '2.2.1.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
}
group 'self.me'
version '1.0-SNAPSHOT'
//sourceCompatibility = 1.8
configurations {
developmentOnly
runtimeClasspath {
extendsFrom developmentOnly
}
}
repositories {
mavenCentral()
}
test {
useJUnitPlatform()
}
dependencies {
compile group: 'org.jetbrains', name: 'annotations', version: '16.0.2'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
// Feed parsing
compile group: 'org.jsoup', name: 'jsoup', version: '1.12.1'
implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.5'
// Video parsing - FFMPEG wrapper
compile group: 'net.bramp.ffmpeg', name: 'ffmpeg', version: '0.6.2'
// SpringBoot
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.flywaydb:flyway-core'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'com.h2database:h2'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
// Testing
def junit_version = '5.4.0'
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: junit_version
testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: junit_version
testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: junit_version
testImplementation group: 'commons-io', name: 'commons-io', version: '2.6'
}
请先登录再写评论。
I solve the similar problem with the method in https://intellij-support.jetbrains.com/hc/en-us/community/posts/360008766800-Test-suite-in-class-will-not-run-No-tests-were-found-
I had a similar issue with a Gradle project and removing the "out" folder resolved it for me.
Before that I was experiencing the issue with both using Intellij and Gradle to run my tests.
My problem was similar to all the reported ones in this thread, where the tests stopped working after moving some classes to another Gradle project and wiring these back via a Maven dependency.
Deleting "out" directory has helped me with other issues in intellij in the past.
Had the same issue with IDEA 2021.2.1 with testng 7.4.0.
Finally just renamed the test class, and ran it successfully, then renamed it back and it just works fine now.
It looks like a failure of caching or smth like this.
Hello Сергей Чернов,
In case the issue reoccurs, please share the idea.log file (Help | Show Log in Finder), you may upload it here: https://uploads.services.jetbrains.com and share the link with us or attach it to the issue created at YouTrack: https://youtrack.jetbrains.com/issues/IDEA
Thank you
I'm getting this in Ultimate 2022.1.1
"No tests were found"
Class not found: "com.telenav.kivakit.core.tests.time.TimeTest"
But the class is definitely there. Is it possible there is a thread sync problem where it's trying to access the class, but it's not available (perhaps in a cache) yet?
Hello Jonathanl,
Can you please file an issue in the YouTrack and attach the sample project where the issue is reproduced for you:
https://youtrack.jetbrains.com/issues/IDEA
Thank you
I can work on that, but could we also add the full stack trace?
"Class not found: "com.telenav.kivakit.internal.tests.core.bits.BitDiagramTest"
Isn't enough to know what happened exactly (for example, it could be an exception in the initializer rather than a missing class, and it would produce that same result).
Aha! I debugged the JUnit test startup and it appears the problem is that the class loader's module list (ClassLoader$AppClassLoader.nameToModule) does not include 'test-classes'. Instead it is using 'classes'. That's why it can't find the class.
This problem is probably occurring in turn because there are two module-info.java files in the tree. One in the test sources and one in the main sources. That is there to fix maven's surefire plugin, which doesn't work unless both trees have a module-info.java. I wonder, is there ever going to be a module-info.java for the test tree?
Fixed it by removing the module-info.java in the test tree. IntelliJ might want to provide a warning or guidance about this if it's detected.
Hey Jonathanl, the module-info.java in the test sources shouldn't create problems for running tests, but it can require some specific settings for maven and module-info files. Pls see a sample project here https://github.com/sergeiJB/antiModules
One of the most useless and uninformative error messages ever.
David Peterson we always address usability problems, but we'll really appreciate if you can specify the exact issue and a perspective on how it can be improved in that case.
You can always ask a question on this platform or open issue here https://youtrack.jetbrains.com/issues/IDEA. It is also possible to leave a feedback for any of guide pages (https://www.jetbrains.com/help/idea) if you miss some information there
This Issue goes arises when we give maven dependency and that dependency have build issues. please remove the dependency and check
Solved it by closing IntelliJ and renaming my .idea folder in the root of my project. Then imported/opened the project again in IntelliJ, a new .idea folder was created. Then ran the tests and now they worked fine. Closed IntelliJ and renamed the old folder back (and deleted the new folder), opened IntelliJ again and the tests still worked! So some hickup seems to have been solved in IntelliJ by this.
Make sure to rename the .idea folder, instead of deleting it. I only realized after renaming the folder that my git stash is also managed by this an all the work of the last hours would have been gone if I simply deleted the folder (ok theres the bin folder, so maybe it wouldnt have been really gone, whatever)
I deleted the Target folder created during a previous execution and ran the test again and it worked.
Like Avanalitekin pointed out deleting the Target folder fixed the problem. So it looks like some kind of caching issue for me. In my case I am using Gradle to build the library so I had to delete the "build" folder. This also allowed by JUnit "All tests" target to include the new tests too.
Resolution → Just Open gradle.
Click on Download Source and Reload Project. That's it. Will solve this.