Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set Hilt's aggregating task test environment flag when configuring the task for a com.android.test Gradle module. #3521

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,8 @@ class HiltGradlePlugin @Inject constructor(
@Suppress("DEPRECATION") // Older variant API is deprecated
it.testEnvironment.set(
variant is com.android.build.gradle.api.TestVariant ||
variant is com.android.build.gradle.api.UnitTestVariant
variant is com.android.build.gradle.api.UnitTestVariant ||
androidExtension is com.android.build.gradle.TestExtension
)
it.crossCompilationRootValidationDisabled.set(
hiltExtension.disableCrossCompilationRootValidation
Expand Down
3 changes: 2 additions & 1 deletion javatests/artifacts/hilt-android/simple/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ include ':feature'
include ':lib'
include ':deep-android-lib'
include ':deep-lib'
include ':earlyentrypoint'
include ':earlyentrypoint'
include ':uitest'
61 changes: 61 additions & 0 deletions javatests/artifacts/hilt-android/simple/uitest/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright (C) 2022 The Dagger Authors.
*
* 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.
*/

apply plugin: 'com.android.test'
apply plugin: 'com.google.dagger.hilt.android'

android {
compileSdkVersion 32
buildToolsVersion "32.0.0"

defaultConfig {
minSdkVersion 15
targetSdkVersion 32
testInstrumentationRunner "dagger.hilt.android.simple.uitest.TestRunner"
missingDimensionStrategy 'tier', 'free'
}
targetProjectPath ':app'
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
}

hilt {
enableAggregatingTask = true
}

dependencies {
implementation project(':app')

implementation 'junit:junit:4.13'
implementation 'androidx.test.ext:junit:1.1.3'
implementation 'androidx.test:runner:1.4.0'

implementation "com.google.dagger:hilt-android:$dagger_version"
implementation "com.google.dagger:hilt-android-testing:$dagger_version"
annotationProcessor "com.google.dagger:hilt-compiler:$dagger_version"
}

configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
if ("$dagger_version" == 'LOCAL-SNAPSHOT'
&& details.requested.group == 'com.google.dagger') {
details.useVersion 'LOCAL-SNAPSHOT'
details.because 'LOCAL-SNAPSHOT should act as latest version.'
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2022 The Dagger Authors.
~
~ 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.
-->

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="dagger.hilt.android.simple.uitest">
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (C) 2022 The Dagger Authors.
*
* 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 dagger.hilt.android.simple.uitest;

import android.app.Application;
import android.content.Context;
import androidx.test.runner.AndroidJUnitRunner;
import dagger.hilt.android.testing.HiltTestApplication;

public final class TestRunner extends AndroidJUnitRunner {
@Override
public Application newApplication(ClassLoader cl, String className, Context context)
throws ClassNotFoundException, IllegalAccessException, InstantiationException {
return super.newApplication(cl, HiltTestApplication.class.getName(), context);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (C) 2022 The Dagger Authors.
*
* 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 dagger.hilt.android.simple.uitest;

import androidx.test.ext.junit.runners.AndroidJUnit4;
import dagger.hilt.android.testing.HiltAndroidTest;
import org.junit.runner.RunWith;

// An empty test file that validates multiple test roots in an com.android.test Gradle module.
@HiltAndroidTest
@RunWith(AndroidJUnit4.class)
public final class UITestOne {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (C) 2022 The Dagger Authors.
*
* 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 dagger.hilt.android.simple.uitest;

import androidx.test.ext.junit.runners.AndroidJUnit4;
import dagger.hilt.android.testing.HiltAndroidTest;
import org.junit.runner.RunWith;

// An empty test file that validates multiple test roots in an com.android.test Gradle module.
@HiltAndroidTest
@RunWith(AndroidJUnit4.class)
public final class UITestTwo {

}