4

I've tried to do some unit test example that included in an Android Studio project like ExampleInstrumentedTest and ExampleUnitTest, so the result is :

Entry name 'res/layout/test_toolbar.xml' collided

I've searched everywhere on google but there's not answers to this specific problem, so any help will be grateful

here's the source of the basic unit test example :

ExampleUnitTest

 * Example local unit test, which will execute on the development machine (host).
 *
 * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
 */
public class ExampleUnitTest {
    @Test
    public void addition_isCorrect() {
        assertEquals(4, 2 + 2);
    }}

enter image description here

ExampleInstrumentedTest

 * Instrumented test, which will execute on an Android device.
 *
 * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
 */
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
    @Test
    public void useAppContext() {
        // Context of the app under test.
        Context appContext = InstrumentationRegistry.getInstrumentation().getContext();

        assertEquals("com.example.abder.emarque", appContext.getPackageName());
    }}

enter image description here

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Abderazak Amiar
  • 776
  • 7
  • 22

2 Answers2

0

I just did the following and It solved my problem.

  1. Invalidate caches and Restart (File -> Invalidate Caches / Restart)
  2. Clean Project (Build -> Clean Project)
0

This happens due to same xml may be included in third party SDKs. Solution: exclude 'res/layout/test_toolbar.xml' in packagingOptions of app's build.gradle file.

packagingOptions { exclude 'res/layout/test_toolbar.xml' }