DaveAKing / guava-libraries

Automatically exported from code.google.com/p/guava-libraries
Apache License 2.0
0 stars 0 forks source link

AbstractPackageSanityTests picks up test-utility classes #1535

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
When using AbstractPackageSanityTests for a package, I get this error:

junit.framework.AssertionFailedError: Error in automated nulls test of class 
com.spotify.nameless.api.HermesMessageMatcher
If the class is better tested explicitly, you can add testNulls() to 
com.spotify.nameless.api.HermesMessageMatcherTest
    at com.google.common.testing.AbstractPackageSanityTests.sanityError(AbstractPackageSanityTests.java:272)
    at com.google.common.testing.AbstractPackageSanityTests.testNulls(AbstractPackageSanityTests.java:209)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:84)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:77)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:195)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: junit.framework.AssertionFailedError: No exception thrown from 
protected boolean 
com.spotify.nameless.api.HermesMessageMatcher.matchesSafely(com.spotify.hermes.m
essage.Message)[null] for class com.spotify.nameless.api.HermesMessageMatcher
    at com.google.common.testing.NullPointerTester.testParameter(NullPointerTester.java:338)
    at com.google.common.testing.NullPointerTester.testMethodParameter(NullPointerTester.java:207)
    at com.google.common.testing.NullPointerTester.testMethod(NullPointerTester.java:175)
    at com.google.common.testing.NullPointerTester.testInstanceMethods(NullPointerTester.java:141)
    at com.google.common.testing.ClassSanityTester.doTestNulls(ClassSanityTester.java:193)
    at com.google.common.testing.AbstractPackageSanityTests.testNulls(AbstractPackageSanityTests.java:207)
    ... 22 more

The HermesMessageMatcher is a custom hamcrest matcher (see for instance 
https://code.google.com/p/hamcrest/wiki/Tutorial) that I created to make the 
unit tests more readable. It's of course not something I'd like the package 
tests to pick up. I can see two possible options for fixing this:

1. Make the findClassesToTest() method exclude classes that live in the 
target/test-classes directory (or perhaps in some configurable directory for 
those who don't use Maven). This information would seem to be present in the 
ClassPath.ClassInfo, but not as far as I can tell in the Class<?>, so things 
would have to move around a bit.
2. Make it easy for users to define classes that should be excluded from tests 
entirely. It is possible to work around this by creating an empty test class 
that has empty implementations of those tests that one doesn't want to run, but 
that's quite awkward and unintuitive.

Original issue reported on code.google.com by petterma...@gmail.com on 16 Sep 2013 at 1:03

GoogleCodeExporter commented 9 years ago

Original comment by lowas...@google.com on 25 Sep 2013 at 9:54

GoogleCodeExporter commented 9 years ago
Can ignoreClasses(Predicate) be used?

Original comment by be...@google.com on 25 Sep 2013 at 9:57

GoogleCodeExporter commented 9 years ago
Yes, that does work. I didn't spot that method despite spending a fair amount 
of time reading the code. Thanks for pointing it out!

It might be a good idea to try to improve the documentation a little with 
regard to the use of methods like setDefault(Class, Object), 
ignoreClasses(Predicate), etc. For me at least, it's been a bit of a 
struggle/surprise when running into issues with those.

Thanks again for the help!

Original comment by petterma...@gmail.com on 26 Sep 2013 at 7:21

GoogleCodeExporter commented 9 years ago
http://code.google.com/p/guava-libraries/source/detail?r=57e66d83a43c65827468ba2
a7f5af550097d1bc3

Hope that helps.

Original comment by cpov...@google.com on 8 Oct 2013 at 3:52

GoogleCodeExporter commented 9 years ago
This issue has been migrated to GitHub.

It can be found at https://github.com/google/guava/issues/<issue id>

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:12

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 3 Nov 2014 at 9:08