简体   繁体   中英

How can I quickly create a class in the right place when following TDD using Visual Studio/ReSharper?

Suppose I'm following TDD and using VS/ReSharper. I start out writing a test like this:

[TestFixture]
class FooFixture
{
    [Test]
    public void ShouldDoSomething()
    {
        var foo = new Foo();
    } 
}

At this point, Foo doesn't exist. ReSharper suggests the option of creating the class, but it puts it right next to my test class in my test project, not in my real project. So I have it create the class, then move it to a new file, then move the file to the right place, and finally fix the namespace. This seems like a lot of work.

Is there a more efficient way to quickly create the Foo class and put it in the right place? It seems like the 'right place' could be guessed from the namespace of my test project.

Move types into matching class refactoring is used for this purpose.

You're expected to generate a number of business logic types in the current test class and then move them to matching files/namespaces in one go.

Note that this refactoring is available in the text editor and on Solution Explorer nodes, meaning that you can batch-apply it to a heck lot of files.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM