Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bcf1a9c3 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "[Ravenwood] Support JUnit's Suite runner" into main

parents 1155ac51 f10a363d
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -64,7 +64,7 @@ public class CallTracker {
    /**
     * Check the number of calls stored in {@link #mNumCalled}.
     */
    protected void assertCalls(Object... methodNameAndCountPairs) {
    public void assertCalls(Object... methodNameAndCountPairs) {
        // Create a local copy
        HashMap<String, Integer> counts = new HashMap<>(mNumCalled);
        for (int i = 0; i < methodNameAndCountPairs.length - 1; i += 2) {
@@ -95,7 +95,7 @@ public class CallTracker {
     * Same as {@link #assertCalls(Object...)} but it kills the process if it fails.
     * Only use in @AfterClass.
     */
    protected void assertCallsOrDie(Object... methodNameAndCountPairs) {
    public void assertCallsOrDie(Object... methodNameAndCountPairs) {
        try {
            assertCalls(methodNameAndCountPairs);
        } catch (Throwable th) {
+49 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.ravenwoodtest.bivalenttest.ravenizer;

import android.platform.test.annotations.NoRavenizer;
import android.platform.test.ravenwood.RavenwoodAwareTestRunner.RavenwoodTestRunnerInitializing;

import org.junit.Test;

/**
 * Test for {@link android.platform.test.annotations.NoRavenizer}
 */
@NoRavenizer
public class RavenwoodNoRavenizerTest {
    public static final String TAG = "RavenwoodNoRavenizerTest";

    private static final CallTracker sCallTracker = new CallTracker();

    /**
     * With @NoRavenizer, this method shouldn't be called.
     */
    @RavenwoodTestRunnerInitializing
    public static void ravenwoodRunnerInitializing() {
        sCallTracker.incrementMethodCallCount();
    }

    /**
     * Make sure ravenwoodRunnerInitializing() wasn't called.
     */
    @Test
    public void testNotRavenized() {
        sCallTracker.assertCalls(
                "ravenwoodRunnerInitializing", 0
        );
    }
}
+69 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.ravenwoodtest.bivalenttest.ravenizer;

import android.util.Log;

import org.junit.AfterClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;

/**
 * Test to make sure {@link Suite} works with the ravenwood test runner.
 */
@RunWith(Suite.class)
@Suite.SuiteClasses({
        RavenwoodSuiteTest.Test1.class,
        RavenwoodSuiteTest.Test2.class
})
public class RavenwoodSuiteTest {
    public static final String TAG = "RavenwoodSuiteTest";

    private static final CallTracker sCallTracker = new CallTracker();

    @AfterClass
    public static void afterClass() {
        Log.i(TAG, "afterClass called");

        sCallTracker.assertCallsOrDie(
                "test1", 1,
                "test2", 1
        );
    }

    /**
     * Workaround for the issue where tradefed won't think a class is a test class
     * if it has a @RunWith but no @Test methods, even if it is a Suite.
     */
    @Test
    public void testEmpty() {
    }

    public static class Test1 {
        @Test
        public void test1() {
            sCallTracker.incrementMethodCallCount();
        }
    }

    public static class Test2 {
        @Test
        public void test2() {
            sCallTracker.incrementMethodCallCount();
        }
    }
}
+2 −1
Original line number Diff line number Diff line
@@ -57,7 +57,8 @@ public class RavenwoodAwareTestRunnerHook {
     */
    public static void onRunnerInitializing(Runner runner, TestClass testClass) {
        // This log call also ensures the framework JNI is loaded.
        Log.i(TAG, "onRunnerInitializing: testClass=" + testClass + " runner=" + runner);
        Log.i(TAG, "onRunnerInitializing: testClass=" + testClass.getJavaClass()
                + " runner=" + runner);

        // TODO: Move the initialization code to a better place.

+36 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.platform.test.annotations;

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

/**
 * Disable the ravenizer preprocessor for a class. This should be only used for testing
 * ravenizer itself, or to workaround issues with the preprocessor. A test class probably won't run
 * properly if it's not preprocessed.
 *
 * @hide
 */
@Inherited
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface NoRavenizer {
}
Loading