# How to prevent refactor in tests with \`moveFile\` method

**URL:** <https://platform.jetbrains.com/t/how-to-prevent-refactor-in-tests-with-movefile-method/1034>\
**Category:** IntelliJ Platform\
**Created:** [March 21, 2025, 10:33am UTC](https://platform.jetbrains.com/t/how-to-prevent-refactor-in-tests-with-movefile-method/1034 "2025-03-21T10:33:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gtchaboussie](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/gtchaboussie/32/737_2.png) [@gtchaboussie](https://platform.jetbrains.com/u/gtchaboussie)\
**Post date:** [March 21, 2025, 10:33am UTC](https://platform.jetbrains.com/t/how-to-prevent-refactor-in-tests-with-movefile-method/1034/1 "2025-03-21T10:33:15Z")

</div>

Hi all.  
I’m having an issue when writing tests.  
I need some assets to be able to run my tests. In the `setup` method,  
i copy an `assets` directory in my test project and then move my test file inside this directory.  
But when doing so (moving the file), the ide seems to prerform refactoring even though it completely breaks my tests.

This is the file before

```xml

<screens xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://ofbiz.apache.org/Widget-Screen"
         xsi:schemaLocation="http://ofbiz.apache.org/Widget-Screen http://ofbiz.apache.org/dtds/widget-screen.xsd">
    <screen name="Foo">
        <section>
            <widgets>
                <include-screen name="DuplicatedTargetScreen" location="component://zelda/widget/DuplicatedTargetScreens.xml"/>
            </widgets>
        </section>
    </screen>
</screens>

```

This is the test code

```groovy
void testDuplicatedTargetScreen() {
    String desc = message('inspection.screen.duplicate.display.descriptor')
    myFixture.enableInspections(new DuplicatedScreenInspection())
    String file = "${this.getTestName(false)}.xml"
    String dest = 'zelda/widget'
    myFixture.moveFile("xml/$file", dest)
    myFixture.configureByFile("$dest/$file")
    doHighlight(true, desc)
}

protected void doHighlight(boolean mustFind, String desc) {
    List<HighlightInfo> highlightInfos = myFixture.doHighlighting()
    List<String> highlightDescs = highlightInfos.collect { it.description }
    if (!mustFind) {
        assert !highlightDescs.contains(desc)
    } else {
        assertFalse highlightInfos.isEmpty()
        assert highlightDescs.contains(desc)
    }
}

```

And this is the test file after (I used debug to get the file content)

```xml
<screens xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://ofbiz.apache.org/Widget-Screen"
         xsi:schemaLocation="http://ofbiz.apache.org/Widget-Screen http://ofbiz.apache.org/dtds/widget-screen.xsd">

    <screen name="Foo">
        <section>
            <widgets>
                <include-screen name="DuplicatedTargetScreen" location="../../elden/widget/EldenScreens.xml"/>
            </widgets>
        </section>
    </screen>
</screens>

```

Notice the `location` attribute value that has been modified.  
Is there a way to prevent refactoring in tests while moving files ? It kinda kills the tests  
Thanks

---

<div class="post-metadata">

**Author:** ![yann.cebron](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/yann.cebron/32/15_2.png) [@yann.cebron](https://platform.jetbrains.com/u/yann.cebron)\
**Post date:** [March 24, 2025, 9:20am UTC](https://platform.jetbrains.com/t/how-to-prevent-refactor-in-tests-with-movefile-method/1034/2 "2025-03-24T09:20:27Z")

</div>

1. Parametrize `setup()` and copy files to expected location for each test. You can use custom annotation for each test or use test name, for example.
2. perform such setup in each test method with dedicated path “manually”

---

<div class="post-metadata">

**Author:** ![gtchaboussie](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/gtchaboussie/32/737_2.png) [@gtchaboussie](https://platform.jetbrains.com/u/gtchaboussie)\
**Post date:** [March 24, 2025, 4:51pm UTC](https://platform.jetbrains.com/t/how-to-prevent-refactor-in-tests-with-movefile-method/1034/4 "2025-03-24T16:51:43Z")

</div>

I already do such configs in `setup`. But idealy all my test files (with in) are stored in a consistant way. Considering most tests do not need to do a `move` it breaks the logic.  
That’s why i didn’t thought about copying the file the test is run against in the setup.  
But that should work thanks 🙂
