You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Android Studio Arctic Fox | 2020.3.1中运行JUnit测试?旧Android JUnit运行配置在新版Android Studio中无法运行的问题咨询

Fixing Android JUnit Run Configuration Error in Arctic Fox (2020.3.1)

Hey there, I’ve run into this exact issue when upgrading to Android Studio Arctic Fox—those old AndroidJUnit configurations get deprecated pretty quickly. Let’s walk through how to fix this step by step:

Why This Error Happens

Starting with Arctic Fox, Google deprecated the old AndroidJUnit run configurations because Gradle is now the official, more reliable way to manage and run unit tests for Android projects. The IDE is nudging you to switch to Gradle-native test tasks instead of the legacy IDE-specific configs.


Step 1: Remove the Deprecated AndroidJUnit Configuration

First, let’s get rid of that old appTests config that’s causing the error:

  • Click the run/debug dropdown in the top-right corner of Android Studio, then select Edit Configurations...
  • In the left-hand list, find the appTests entry under Android JUnit
  • Select it, click the minus (-) button at the top-left to delete it, then hit Apply and OK

You don’t need to manually edit the .idea/workspace.xml file—deleting the config through the IDE will handle that cleanly for you.


Step 2: Run Unit Tests Using Gradle (3 Easy Ways)

Now you can run your tests using Gradle, which is the recommended approach. Here are the most convenient methods:

Option 1: Use the Gradle Tool Window

  • Open the Gradle tool window (if it’s hidden, go to View > Tool Windows > Gradle)
  • Expand your project: myproject-android > app > Tasks > verification
  • To run all unit tests for your debug build variant, double-click testDebugUnitTest (use testReleaseUnitTest for release builds)
  • Want to run a specific package/class/method? Right-click the testDebugUnitTest task, select Modify Run Configuration, then add a filter in the Arguments field:
    • For a package: --tests "com.yourproject.package.*"
    • For a single class: --tests "com.yourproject.package.YourTestClass"
    • For a single method: --tests "com.yourproject.package.YourTestClass.yourTestMethod"

Option 2: Right-Click Directly in Your Test Code

This is the fastest way for ad-hoc testing:

  • Open any JUnit test class or method
  • Right-click the class name (to run all tests in the class) or the method name (to run just that test)
  • Select Run 'YourTestClass' or Run 'yourTestMethod'
  • Android Studio will automatically create a new Gradle-based run configuration for you, which you can reuse later from the run dropdown.

Option 3: Create a Custom Gradle Run Configuration (For Reuse)

If you want a dedicated, reusable config for your tests:

  • Open Edit Configurations... again, click the plus (+) button, and select Gradle
  • Give your config a name (e.g., App Debug Unit Tests)
  • Under Gradle project, select your app module
  • In the Tasks field, enter testDebugUnitTest (adjust for your build variant if needed)
  • Add any test filters in the Arguments field if you want to target specific tests
  • Hit Apply and OK—you can now run this config anytime from the run dropdown.

Wrap-Up

Switching to Gradle-based test runs not only fixes this error but also aligns your testing workflow with Android’s official build system, making tests more consistent across different environments (like CI/CD pipelines).

内容的提问来源于stack exchange,提问作者NickUnuchek

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 08:42:36