0

このブログのリフレクションの例を使用しようとしています: https://github.com/ronmamo/reflections

私のjunitコードで@unitTestsで注釈が付けられたクラスのリストを取得します。

以下は私がやったことです:

//imports here...
@RunWith(CustomRunner.UnitRunner.class)
public class CustomRunner {

private CustomRunner{}
public static class UnitRunner extends Suite {
        public UnitRunner(final Class<?> clazz) throws InitializationError {
            super(clazz, findClasses());
        }

 private static Class<?>[] findClasses() {
            if (System.getProperty(MODE_VM_ARG) == null) {
                String message = "Please supply run mode VM arg -DMODE=...";
                JOptionPane.showMessageDialog(null, message);
                System.exit(-1);
            }
            List<File> classFiles = new ArrayList<File>();
            List<Class<?>> classes = convertToClasses(classFiles);

private static List<Class<?>> convertToClasses(final List<File> classFiles) {
Reflections reflections = new Reflections("com.drWho.myUnitTests");
     Set<Class<?>> annotatedWithUnitTest = reflections.getTypesAnnotatedWith(UnitTest.class);
//...more other stuffs down here..
}

}
//class ends some where....doesn't really matter


****//my unitTest annotated class****



package com.com.drWho.utils;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface UnitTest {

}

リフレクションは、コンストラクターで提供されたパッケージから単体テスト クラスを見つけることができないようです。理由がわからない。私が間違っていることはありますか?

ありがとう

4

0 に答える 0