无法在visual studio中调试单元测试

时间:2022-10-15 20:34:19

I have the following xUnit unit test that is throwing nullReferenceException.

我有以下xUnit单元测试抛出nullReferenceException。

So I decided to debug. However, when I debug my test fails before even it hits the first break point.

所以我决定调试。但是,当我调试我的测试失败之前,即使它遇到第一个断点。

How do I fix this?

我该如何解决?

无法在visual studio中调试单元测试

5 个解决方案

#1


3  

Before you run your unit tests the next time, hit CTRL-D, E to bring up the Debug | Exceptions window. To make it quicker, just put a check next to CLR Exceptions in the Thrown column. Now run. Hopefully, execution will break at the source of your NullReferenceException.

在下次运行单元测试之前,按CTRL-D,E调出Debug |例外窗口。为了更快,只需在“已抛出”列中的“CLR异常”旁边选中一个复选框。现在跑。希望执行将在NullReferenceException的源处中断。

#2


1  

Seems like you've got an error that occurs before your test method. I'd check the constructor. It might be the test initialization code there.

好像你在测试方法之前发生了一个错误。我检查构造函数。它可能是那里的测试初始化​​代码。

#3


1  

I had a similar issue in Visual Studio 2017. The unit test project was added automatically by the framework. I read many blogs, and nothing was able to solve my issue. Finally I got it to work using the following approach: At the Solution Level, Right Click => Properties=> Set them to Debug mode.

我在Visual Studio 2017中遇到了类似的问题。框架自动添加了单元测试项目。我读了很多博客,没有什么能解决我的问题。最后,我使用以下方法使其工作:在解决方案级别,右键单击=>属性=>将它们设置为调试模式。

#4


0  

Do you have methods with the xUnit-equivalents of MSTest's [ClassInitialize] or [TestInitialize] attributes? If one of those is throwing your NullReferenceException, that could be why it's not hitting your breakpoint.

你有使用MSTest的[ClassInitialize]或[TestInitialize]属性的xUnit等价的方法吗?如果其中一个抛出你的NullReferenceException,那么这可能就是它没有碰到你的断点的原因。

#5


0  

I am not familiar with xUnit, but it sounds like your test class either:

我不熟悉xUnit,但它听起来像你的测试类:

  1. Fails in init method or constructor

    在init方法或构造函数中失败

  2. Can not be created from its DLL.

    无法从其DLL创建。

Make sure you ate copying any dependant DLLs and resources to test execution dir on static class int, prior to constructor of class bring called.

确保你在调用类的构造函数之前,先复制任何依赖的DLL和资源来测试静态类int上的执行目录。

#1


3  

Before you run your unit tests the next time, hit CTRL-D, E to bring up the Debug | Exceptions window. To make it quicker, just put a check next to CLR Exceptions in the Thrown column. Now run. Hopefully, execution will break at the source of your NullReferenceException.

在下次运行单元测试之前,按CTRL-D,E调出Debug |例外窗口。为了更快,只需在“已抛出”列中的“CLR异常”旁边选中一个复选框。现在跑。希望执行将在NullReferenceException的源处中断。

#2


1  

Seems like you've got an error that occurs before your test method. I'd check the constructor. It might be the test initialization code there.

好像你在测试方法之前发生了一个错误。我检查构造函数。它可能是那里的测试初始化​​代码。

#3


1  

I had a similar issue in Visual Studio 2017. The unit test project was added automatically by the framework. I read many blogs, and nothing was able to solve my issue. Finally I got it to work using the following approach: At the Solution Level, Right Click => Properties=> Set them to Debug mode.

我在Visual Studio 2017中遇到了类似的问题。框架自动添加了单元测试项目。我读了很多博客,没有什么能解决我的问题。最后,我使用以下方法使其工作:在解决方案级别,右键单击=>属性=>将它们设置为调试模式。

#4


0  

Do you have methods with the xUnit-equivalents of MSTest's [ClassInitialize] or [TestInitialize] attributes? If one of those is throwing your NullReferenceException, that could be why it's not hitting your breakpoint.

你有使用MSTest的[ClassInitialize]或[TestInitialize]属性的xUnit等价的方法吗?如果其中一个抛出你的NullReferenceException,那么这可能就是它没有碰到你的断点的原因。

#5


0  

I am not familiar with xUnit, but it sounds like your test class either:

我不熟悉xUnit,但它听起来像你的测试类:

  1. Fails in init method or constructor

    在init方法或构造函数中失败

  2. Can not be created from its DLL.

    无法从其DLL创建。

Make sure you ate copying any dependant DLLs and resources to test execution dir on static class int, prior to constructor of class bring called.

确保你在调用类的构造函数之前,先复制任何依赖的DLL和资源来测试静态类int上的执行目录。