I'm looking for ways to quickly debug the code I've just written to see if it behaves correctly and all my assumptions are correct. I don't want to run the full system yet because parts of infrastructure to get to this code are missing. I use unit testing for it but I find it cumbersome. Is there anything better?
Objectives are:
- Debug any code quickly without creating additional projects, applications etc.
- Easily repeat debugging.
- The test is for this specific purpose, might use fixed file paths, database connections, anything. Typically thrown away after getting things right.
- Need to access internal members of my objects.
- Accessing private member would be great benefit.
- I'm fine with writing test functions directly in my object. Actually this would be preferred.
The dream way of doing it would be:
namespace Aaa
{
class SomeClass
{
public string Name { get; private set; }
public SomeClass(string name, int value)
{
this.Name = name;
InitializeSth();
}
public DoSomethingPublic()
{
// ...
}
private DoSomethingPrivate()
{
// ...
}
public static void TestThis() // <-- debug this
{
var obj = new SomeClass(); // <-- put breakpoint here
obj.DoSomethingPublic();
obj.DoSomethingPrivate();
}
}
}
This is possible in Java and is such a great thing. This allows for accessing private things too.
But I'm open to other options as well. Is there anything like this in VS2015?
What I have tried so far:
- Immediate Window - I don't think it can be configured for such purpose
- C# Interactive - this doesn't seem to support debugging. Or does it?
- Unit testing - this is what I use now (with MSTest). But I find it very cumbersome, because:
- I need to create new projects, or include references to MS testing assemblies
- I need to make extra steps to access internal types and members, or change things to public (I don't like this).
- Even more steps to access private members.
- I mess with other tests if Unit Testing is used in the project.
- Starting debugging again needs many clicks instead of sth+sth+F5.
- There are some workarounds for some of these items, but in general the testing infrastructure seems to be made for a different things and I always have a feeling I'm fighting with it.
I also found some information about Resharper having ability to debug any static function. But I don't want to use Resharper, mainly because of performance.
Aucun commentaire:
Enregistrer un commentaire