-1

I'm trying to use Java ServiceLoader in Scala 2.10 to find all my test classes by reflection:

  val services = ServiceLoader.load(classOf[MyClass])
  for (service <- services.asScala) {
    test(service.getClass.getCanonicalName) {
      println(service)
      ... test code
    }
  }

I'm very sure 'MyClass' has several subclasses which contains test cases, as I can use 'classOf[]' function to find them in the same code snippet

However, my test always ends with

Empty test suite.

Is the ServiceLoader not working in Scala? How to fix or circumvent this problem?

tribbloid
  • 4,026
  • 14
  • 64
  • 103
  • 1
    You didn't even show enough code to see where that "Empty test suite." message comes from. What happens if you dump `services` right at the beginning? Have you tried interactive debugging? Where's your `META-INF/services/` file? – chrylis -cautiouslyoptimistic- Oct 28 '15 at 02:18
  • you are right the META-INF/services/ is missing, looks like its not a fully automatic class detector. The Empty test suite message is thrown by scala test in the loop – tribbloid Oct 28 '15 at 03:48

1 Answers1

1

Sorry I forgot to set the META-INF/services/ file, after adding the binary name of the service class everything goes normal!

tribbloid
  • 4,026
  • 14
  • 64
  • 103
  • 2
    Explain what to do with services folder – Ozan Kurt Jun 13 '16 at 03:01
  • 1
    @OzanKurt Probably write `com.example.impl.MyInterfaceImpl` in the file `META-INF/services/com.example.MyInterface` https://stackoverflow.com/questions/17531625/how-to-include-a-config-file-in-the-meta-inf-services-folder-of-a-jar-using-ma – Dmytro Mitin Dec 15 '22 at 07:35