- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用Cassini/WebServer.WebDev使用NUnit运行WebService的一些自动化测试。
我什么都没做,只是
public class WebService{
Microsoft.VisualStudio.WebHost.Server _server;
public void Start(){
_server = new Microsoft.VisualStudio.WebHost.Server(_port, "/", _physicalPath);
}
public void Dispose()
{
if (_server != null)
{
_server.Stop();
_server = null;
}
}
}
[TestFixture]
public void TestFixture{
[Test]
public void Test(){
using(WebService webService = new WebService()){
webService.Start();
// actual test invoking the webservice
}
}
}
NUnit version 2.5.0.9015 (Beta-2)
Copyright (C) 2002-2008 Charlie Poole.\r\nCopyright (C) 2002-2004 James W. Newki
rk, Michael C. Two, Alexei A. Vorontsov.\r\nCopyright (C) 2000-2002 Philip Craig
.\r\nAll Rights Reserved.
Runtime Environment -
OS Version: Microsoft Windows NT 6.0.6001 Service Pack 1
CLR Version: 2.0.50727.1434 ( Net 2.0.50727.1434 )
ProcessModel: Default DomainUsage: Default
Execution Runtime: net-2.0.50727.1434
.....
Tests run: 5, Errors: 0, Failures: 0, Inconclusive: 0 Time: 28,4538451 seconds
Not run: 0, Invalid: 0, Ignored: 0, Skipped: 0
Unhandled exceptions:
1) TestCase1 : System.AppDomainUnloadedException: Attempted to access an unloaded AppDomain.
2) TestCase2 : System.AppDomainUnloadedException: Attempted to access an unloaded AppDomain.
3) TestCase3 : System.AppDomainUnloadedException: Attempted to access an unloaded AppDomain.
4) TestCase4 : System.AppDomainUnloadedException: Attempted to access an unloaded AppDomain.
[...]
The thread 0x1974 has exited with code 0 (0x0).
############################################################################
############## S U C C E S S #################
############################################################################
Executed tests : 5
Ignored tests : 0
Failed tests : 0
Unhandled exceptions : 4
Total time : 25,7092944 seconds
############################################################################
The thread 0x1bd4 has exited with code 0 (0x0).
The thread 0x10f8 has exited with code 0 (0x0).
The thread '<No Name>' (0x1a80) has exited with code 0 (0x0).
A first chance exception of type 'System.AppDomainUnloadedException' occurred in System.Web.dll
##### Unhandled Exception while running
System.AppDomainUnloadedException: Attempted to access an unloaded AppDomain.
at System.Web.Hosting.ApplicationManager.HostingEnvironmentShutdownComplete(String appId, IApplicationHost appHost)
at System.Web.Hosting.HostingEnvironment.OnAppDomainUnload(Object unusedObject, EventArgs unusedEventArgs)
A first chance exception of type 'System.Threading.ThreadAbortException' occurred in mscorlib.dll
A first chance exception of type 'System.Threading.ThreadAbortException' occurred in mscorlib.dll
A first chance exception of type 'System.Threading.ThreadAbortException' occurred in System.Web.dll
The thread 0x111c has exited with code 0 (0x0).
The program '[0x1A64] nunit-console.exe: Managed' has exited with code -100 (0xffffff9c).
最佳答案
我有同样的问题,但是没有使用卡西尼号。取而代之的是,我有自己的基于System.Net.HttpListener
的Web服务器托管,并通过System.Web.HttpRuntime
在ASP.Net支持下在System.Web.Hosting.ApplicationHost.CreateApplicationHost()
创建的不同应用程序域中运行,并具有ASP.Net支持。这基本上是Cassini的工作方式,除了Cassini在套接字层工作并实现System.Net.HttpListener
本身提供的许多功能之外。
无论如何,要解决我的问题,我需要在让NUnit卸载应用程序域之前调用System.Web.HttpRuntime.Close()
。为此,我在主机代理类中公开了一个新的Close()
方法,该方法由[SetupFixture]类的[TearDown]方法调用,该方法称为System.Web.HttpRuntime.Close()
。
我通过.Net Reflector查看了Cassini实现,尽管它使用了System.Web.HttpRuntime.ProcessRequest()
,但似乎没有在任何地方调用System.Web.HttpRuntime.Close()
。
我不确定如何继续使用预建的Cassini实现(Microsoft.VisualStudio.WebHost.Server
),因为您需要让System.Web.HttpRuntime.Close()
调用发生在由Cassini创建的应用程序域中,以托管ASP.Net。
作为引用,这是我的带有嵌入式Web托管的工作单元测试的一些内容。
我的WebServerHost
类是一个很小的类,它允许将请求编码到System.Web.Hosting.ApplicationHost.CreateApplicationHost()
创建的应用程序域中。
using System;
using System.IO;
using System.Web;
using System.Web.Hosting;
public class WebServerHost :
MarshalByRefObject
{
public void
Close()
{
HttpRuntime.Close();
}
public void
ProcessRequest(WebServerContext context)
{
HttpRuntime.ProcessRequest(new WebServerRequest(context));
}
}
WebServerContext
类只是对从System.MarshalByRefObject派生的
System.Net.HttpListenerContext
实例的包装,以允许来自新ASP.Net托管域的调用回叫到我的域中。
using System;
using System.Net;
public class WebServerContext :
MarshalByRefObject
{
public
WebServerContext(HttpListenerContext context)
{
this.context = context;
}
// public methods and properties that forward to HttpListenerContext omitted
private HttpListenerContext
context;
}
WebServerRequest
类只是抽象
System.Web.HttpWorkerRequest
类的实现,该类通过
WebServerContext
类从ASP.Net托管域回调回我的域。
using System;
using System.IO;
using System.Web;
class WebServerRequest :
HttpWorkerRequest
{
public
WebServerRequest(WebServerContext context)
{
this.context = context;
}
// implementation of HttpWorkerRequest methods omitted; they all just call
// methods and properties on context
private WebServerContext
context;
}
WebServer
类是用于启动和停止Web服务器的 Controller 。启动时,将使用我的
WebServerHost
类作为代理来创建ASP.Net托管域,以允许进行交互。还启动了
System.Net.HttpListener
实例,并启动了一个单独的线程来接受连接。建立连接后,将再次通过
WebServerHost
类在线程池中启动工作线程来处理请求。最终,当Web服务器停止时,监听器停止, Controller 等待接受连接的线程退出,然后关闭监听器。
最后,还可以通过调用WebServerHost.Close()
方法来关闭HTTP运行时。
using System;
using System.IO;
using System.Net;
using System.Reflection;
using System.Threading;
using System.Web.Hosting;
class WebServer
{
public static void
Start()
{
lock ( typeof(WebServer) )
{
// do not start more than once
if ( listener != null )
return;
// create web server host in new AppDomain
host =
(WebServerHost)ApplicationHost.CreateApplicationHost
(
typeof(WebServerHost),
"/",
Path.GetTempPath()
);
// start up the HTTP listener
listener = new HttpListener();
listener.Prefixes.Add("http://*:8182/");
listener.Start();
acceptConnectionsThread = new Thread(acceptConnections);
acceptConnectionsThread.Start();
}
}
public static void
Stop()
{
lock ( typeof(WebServer) )
{
if ( listener == null )
return;
// stop listening; will cause HttpListenerException in thread blocked on GetContext()
listener.Stop();
// wait connection acceptance thread to exit
acceptConnectionsThread.Join();
acceptConnectionsThread = null;
// close listener
listener.Close();
listener = null;
// close host
host.Close();
host = null;
}
}
private static WebServerHost
host = null;
private static HttpListener
listener = null;
private static Thread
acceptConnectionsThread;
private static void
acceptConnections(object state)
{
while ( listener.IsListening )
{
try
{
HttpListenerContext context = listener.GetContext();
ThreadPool.QueueUserWorkItem(handleConnection, context);
}
catch ( HttpListenerException e )
{
// this exception is ignored; it will be thrown when web server is stopped and at that time
// listening will be set to false which will end the loop and the thread
}
}
}
private static void
handleConnection(object state)
{
host.ProcessRequest(new WebServerContext((HttpListenerContext)state));
}
}
Initialization
类用于在单元测试开始时启动Web服务器,并在完成单元测试后将其关闭。
using System;
using NUnit.Framework;
[SetUpFixture]
public class Initialization
{
[SetUp]
public void
Setup()
{
// start the local web server
WebServer.Start();
}
[TearDown]
public void
TearDown()
{
// stop the local web server
WebServer.Stop();
}
}
关于.net - Cassini/WebServer.WebDev,NUnit和AppDomainUnloadedException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/561402/
使用捆绑的 NUnit 工具配置了 NUnit 步骤,如下所示: 执行步骤后,我在日志开头出现以下消息时遇到困难: The TeamCity NUnit runner requires the fol
是否可以定义自定义过滤器,以便 NUnit 仅运行特定测试?我的许多 Nunit 测试都标有自定义属性“BugId”。是否可以编写一个过滤器,以便我可以传入一个数字并仅使用该属性和数字运行测试?如果是
已结束。此问题正在寻求书籍、工具、软件库等的推荐。它不满足Stack Overflow guidelines 。目前不接受答案。 我们不允许提出寻求书籍、工具、软件库等推荐的问题。您可以编辑问题,以便
我想使用 NUnit 来运行 GUI/集成测试。我想做的是在所有测试之前初始化一些自定义报告(来 self 们使用的 GUI 测试框架),并在整个套件运行后运行报告导出。 是否有一些“ super ”
我需要从不同的单元调用测试以在我当前的单元中使用(我指的单元是类)。 NUnit 是否有基础设施可以做到这一点,还是我应该继续做我正在做的事情?实例化类并调用方法? 谢谢! 最佳答案 如果我没理解错的
我将 NUnit 与 CruiseControl.NET 一起使用。我有很多测试项目和程序集。当我运行测试时,在 NUnit 详细信息页面上,它只显示一个程序集,但包含来自所有程序集的所有测试。在日志
我有 13 个独立但相关的架构程序集,以及 13 个独立的 NUnit 测试程序集,每个测试程序集都包含与其匹配的架构程序集的所有测试装置。我正在使用 NUnit 2.5.2(当前最新版本)。 我可以
我可以强制每个 nunit 测试方法在单独的进程上运行吗?我需要这样做,因为调用一些被测方法可能会产生副作用。因此,我需要确保每个单元测试都与其他单元测试完全隔离运行。 最佳答案 您可以使用“/pro
我想在它们运行之前报告它们,并且可以选择通过 shell 脚本运行单个测试而无需管理类别。我们有一些非托管代码可能会使进程处于不良状态,有时很乐意在每次 nunit-console 运行时单独运行每个
我有一些初始化代码来使用我的 API。初始化可能会失败,我想在 NUnit 测试中对其进行测试。 初始化之后,可以使用 API。我也在测试 API,但我所有的测试方法都将使用相同的通用初始化代码。 我
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我已将我的测试配置为在发生故障时最多重试 x 次,以确保故障是合法的,而不是运行期间的侥幸。我没有在初始失败时记录错误消息。 但是,我注意到如果我正在运行测试,第一个测试会失败,然后第二个测试会通过,
由于不清楚的原因,我的 Nunit 测试装置不能在一次运行中执行,所以我被迫在单独的运行中执行一些测试。然而,这意味着测试结果被拆分到多个输出文件中。 是否有可以将 NUnit 结果 XML 文件合并
我创建了一个 NUnit 理论来帮助我测试一些代码。被测试的实际代码对于这个问题并不像我用来测试它的数据那么重要。即,24 小时制中的小时和分钟。 我以这种方式编写我的装置是为了利用这些特性并符合 N
如果我有以下代码: [TestFixture] public class MyBaseTest { protected ISessionManager _sessionManager;
我有一组单元测试,我需要从一个命令行调用中运行它们。其中一个程序集使用与其余程序集不同的配置文件。有没有办法在一个 nunit 项目文件中指定多个应用程序配置文件? 最佳答案 不在项目文件中,但您可以
我已经成功地为 TeamCity 服务器上的每个构建运行了 MSTest。 我有几个使用 NUnit 的项目,所以希望让 TeamCity 运行 NUnit 测试就像运行 MSTests 一样简单:
当我的夜间构建完成时,我会自动运行一些 NUnit 测试。我有一个控制台应用程序检测新构建,然后将构建的 MSI 复制到本地文件夹,并将我的所有组件部署到测试服务器。之后,我在 NUnit dll 中
有没有办法从 TeamCity 的“测试”选项卡中生成 NUnit 测试的可视化结果,目前我的 NAnt 脚本使用以下任务输出结果的 .xml 文件: TIA 最佳答案 可以使用 Te
我们使用 NUnit 来执行集成测试。这些测试非常耗时。通常,检测故障的唯一方法是超时。 我希望一旦检测到单个故障就停止执行测试。 有没有办法做到这一点? 最佳答案 使用 nunit-console,
我是一名优秀的程序员,十分优秀!