2

次のコードを使用して、クライアント側から junit サーブレットにヒットすることによってテスト バンドルが実行される、サーバー側のスリング ユニット テスト ケースを作成していました。私のテストでは、@before を使用して @after またはその他の可能な限り最善の方法でダンプをクリーニングすることにより、この関数に埋め込みたい目的のために実行中の FTP サーバーが必要です。呼び出す実行可能なテストクラスでこれを行う方法junit サーブレット。

@RunWith(SlingRemoteTestRunner.class)
    public class FTPImporterTest extends SlingTestBase implements SlingRemoteTestParameters, SlingTestsCountChecker {
        /**
         *
         */
        public static final String TEST_SELECTOR = "com.my.proj.FTPImporterTesting.FTPImporterServerTest";
        public static final int TESTS_AT_THIS_PATH = 3;
        /**
         *
         */

        public int getExpectedNumberOfTests() { 
            return TESTS_AT_THIS_PATH;
        }

        public String getJunitServletUrl() {
            return getServerBaseUrl() + "/system/sling/junit";
        }

        public String getTestClassesSelector() {
            return TEST_SELECTOR;
        }

        public String getTestMethodSelector() {
            return null;
        }

        public void checkNumberOfTests(int i) {
            Assert.assertEquals(TESTS_AT_THIS_PATH, i);
        }

    }
4

2 に答える 2

0

Sling Teleporter Junit Ruleで新しいアプローチを使用することをお勧めします。クライアント側で実行されるテストを作成できますが、内部の JUnit ステートメントはクライアント側で置き換えられ、junit コア フレームワークを使用して実行される sling でテレポートされます。

ドキュメントの例は次のとおりです。

public class BasicTeleporterTest {

@Rule
public final TeleporterRule teleporter = TeleporterRule.forClass(getClass(), "Launchpad");

@Test
public void testConfigAdmin() throws IOException {
    final String pid = "TEST_" + getClass().getName() + UUID.randomUUID();

    final ConfigurationAdmin ca = teleporter.getService(ConfigurationAdmin.class);
    assertNotNull("Teleporter should provide a ConfigurationAdmin", ca);

    final Configuration cfg = ca.getConfiguration(pid);
    assertNotNull("Expecting to get a Configuration", cfg);
    assertEquals("Expecting the correct pid", pid, cfg.getPid());
}

}

于 2016-06-07T09:30:26.220 に答える