Tag: 测试

可部署的数据库测试方法

我目前正在创建一个使用sql CE数据库的应用程序,我已经使该数据库可以与应用程序一起部署,但是我现在遇到的问题是我需要运行TestMethods但这是错误的当它没有找到数据库,因为它在调试或发布下的“testingProject”文件夹中查找,因为它是数据目录 using (SqlCeConnection sqlCon = new SqlCeConnection(@”Data Source=|DataDirectory|\database.sdf;Persist Security Info=False;”)) 上面的代码是我的连接字符串,所以我猜这意味着测试正在运行并在自己的数据目录中搜索数据库 在不更改数据库连接字符串,数据库位置以及仍然可以部署应用程序的情况下,我可以做些什么的帮助? 还是我问一些不可能的事情? 编辑 [TestMethod] public void TestForReadingFromDB() { List list = class.readDB(); Assert.IsNotNull(list); Assert.AreNotEqual(0, list.Count); } 刚刚添加到当前失败的测试方法中

使用.net检查事件日志中是否记录了事件的最简单方法是什么?

在一段时间内检查事件日志中是否记录了事件的最简单方法是什么? 我想执行一系列自动化测试步骤,然后检查是否有任何错误记录到应用程序事件日志中,忽略了一些我不感兴趣的源。我可以使用System.Diagnostics.EventLog然后查看条目集合,但它似乎不适用于这种情况。 例如,如果事件日志正在删除旧条目,则Entries.Count会随着时间的推移变小。 我更喜欢某种方式来查询日志或监视它在一段时间内的变化。 例如 DateTime start = DateTime.Now; // do some stuff… foreach(EventLogEntry entry in CleverSolution.EventLogEntriesSince(start, “Application”)) { // Now I can do stuff with entry, or ignore if its Source is one // that I don’t care about. // … }

UI自动化按钮样式已启用

我正在评估用于UI测试的UI自动化,我有一个定义了以下按钮的WPF应用程序: 当我需要在视觉上禁用按钮时我只需更改样式,以便用户知道按钮被禁用(颜色已更改)但仍然按钮在内部启用,因此我仍然可以启动OnClick事件以便在显示消息时用户点击“禁用”按钮。 现在问题是我不知道如何从UI Automation检查它当前应用的样式,即按钮是否被禁用或启用。 你知道我怎么能这样做? 在正常情况下,我应该这样做: Automation.Condition cEBtn = new PropertyCondition(AutomationElement.AutomationIdProperty, “MyBtn”); AutomationElement mybtnElement = appRegraceElement.FindFirst(TreeScope.Children, cEBtn); bool disMyBtn = (bool)mybtnElement .GetCurrentPropertyValue(AutomationElement.IsEnabledProperty); 但在我的情况下,按钮始终启用,因此我需要检查应用于按钮的样式。 非常感谢你。 最好的祝福

在Specflow中重用两个要素文件之间的背景定义

我有几个specflow .feature文件来测试web api项目的不同实体。 对于每个实体,我必须在我的数据库中创建一个包含所有所需数据的背景,但在此之前我需要删除所有数据,并且需要使用web api调用删除(而不是通过sql查询)。 我这样做: Background: Given I make a new request to localhost on port 53364 And the path is api/voipport/deleteAll And the request type is Delete When the request has completed Given I make a new request to localhost on port 53364 And the path is api/loopblockingexception/deleteAll And the request type is […]

ASP.NET Core UseSetting来自集成测试

我有一个集成测试项目,在测试类中使用.UseSetting() ,如下所示: public AccessTokenRetrieval() : base(nameof(AccessTokenRetrieval)) { var connectionString = GetConnectionString(); var dbSettings = new DbSettings(connectionString); _userGroupRepository = new UserGroupRepository(dbSettings); _roleRepository = new RoleRepository(dbSettings); _userRepository = new UserRepository(dbSettings); _server = new TestServer(new WebHostBuilder() .UseStartup() .UseEnvironment(“IntegrationTest”) .UseSetting(“IntegrationTestConnString”, dbSettings.IdentityServerConnectionString)); _handler = _server.CreateHandler(); _client = _server.CreateClient(); } 我现在想在我的实际项目的Startup.cs中检索该设置。 我试图这样做: public void ConfigureIntegrationTestServices(IServiceCollection services) { var connectionString = Configuration.GetValue(“IntegrationTestConnString”); […]

登录multithreading环境并进行测试

在以下方案中,请告诉我有关如何设计日志记录以及如何测试日志的建议。 我有一个可以由多个线程调用的API。 单个线程对此API的一次调用会生成50 KB的日志。 是否存在用于在multithreading环境中登录的任何设计模式。 即所有线程的一个日志文件与每个线程的一个专用日志文件 ? 并且,如何测试此function。 (它应该测试吗?) 谢谢。

AppDomain.UnhandledException处理程序不会在unit testing中触发

在下面的代码片段中,为什么在unit testing中抛出exception时,附加的处理程序( AppDomain.CurrentDomain.UnhandledException事件)是否会启动? 我在VS2010上使用NUnit 2.5.10和TestDriven.NET 3.0。 [TestFixture] public class MyTests { private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { Console.WriteLine(“Gotcha!”); } [Test] public void ExceptionTest1() { AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; throw new Exception(“ExceptionInTest”); } } 输出:(没有问题) —— Test started: Assembly: WcfQueue.Test.dll —— Test ‘xxxxx.Test.MyTests.ExceptionTest1’ failed: System.Exception : ExceptionInTest ProgramTests.cs(83,0): at xxxxx.Test.MyTests.ExceptionTest1() 0 passed, 1 failed, 0 skipped, […]

测试 – 将忽略DeploymentItem – outputDirectory

我用 在Local.testsettings中将TestProject1 \ Config \下的所有文件复制到’TestRoot’\ TestConfig \,但它直接在Test’TestRoot’文件夹中复制文件。

命令行自动化 – 期望等效

有一个命令行工具,我们需要编写自动化测试。 我们的测试框架是用C#编写的,我正在寻找可以让我进行自动化的.NET库(我知道我可以使用Process类;重定向IO;进行validation,但我不想重新发明轮子如果可能的话)。 理想情况下,我正在寻找像期待库这样的东西。 有什么建议?

如何测试永远不会执行的代码?

如果已经validation存在无效数字(通过调用另一种方法),则仅调用以下方法。 如何在以下代码段中测试覆盖throw -line? 我知道有一种方法可以将VerifyThereAreInvalidiDigits和此方法合并在一起。 我正在寻找任何其他想法。 public int FirstInvalidDigitPosition { get { for (int index = 0; index < this.positions.Count; ++index) { if (!this.positions[index].Valid) return index; } throw new InvalidOperationException("Attempt to get invalid digit position whene there are no invalid digits."); } } 我也不想写一个unit testing来运行永远不会被执行的代码。