如何实现AssemblyInitialize / AssemblyCleanup在我的codedUITest在2010年MSVS? [英] How do I implement AssemblyInitialize/AssemblyCleanup in my CodedUITest in MSVS 2010?

查看:113
本文介绍了如何实现AssemblyInitialize / AssemblyCleanup在我的codedUITest在2010年MSVS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现的 AssemblyInitialize / AssemblyCleanup 的属性,在我的Microsoft Visual Studio 2010中的确切目的,陈述的此处。这种联系甚至描述了我需要遵循执行code的过程。

这目​​的的简单总结就是创建code的初始块,将任何考试前的运行无论其codedUITests的我在溶液中,然后code块运行其中最后codedUITest完成后将会运行。例如:我需要打开一个特定的应用程序,然后运行一系列codedUITests的所有开始在该应用程序并以任何顺序执行,然后关闭所有应用程序完成后,这比开放更有效/关闭应用程序的每个codedUITest。

我不明白的是,我需要把code。在该页面(如下所示)的底部布局。我坚持下,我的'公共部分类的UIMap'和code同时运行所有code右键除了它运行'OpenApplication'和'CloseApplication前后命令/每codedUITest而不是夹在整个组的codedUITests。

我如何实现code正确?

更新:


  

我发现AssemblyI / C昨晚我花了3小时试图
  找出其中把code所以它的工作原理。如果我把
  在一个具体的测试方法的开头AssemblyInitialize然后


  
  

1),它仍然不会跑 - 这是给我的一些错误,指出
  UIMap.OpenWindow()和UIMap.CloseWindow()方法需要是静态的
  我无法弄清楚如何让他们一成不变的。


  
  

2)岂不具体[TestMethod的],它具有AssemblyI /它ç
  需要在测试组?在我的情况我有一打
  这需要运行单独或在一个较大的codedUITests
  组,我需要得到AssemblyI / C打开/关闭我的窗口
  测试。



解决方案

您已经添加了方法错误的类。通过将然后进入的UIMap 部分类,你告诉运行在每次创建时运行这些方法一个新的的UIMap 实例,它听起来就像你正在做的每一项测试。

ClassInitialize / ClassCleanup 方法的要点是将它们添加到类在它的测试方法。你应该至少有一个类装饰用的TestClass 属性,它至少有一个方法,饰以 TestMethod的属性。这是一个需要应用到它的 ClassInitialize ClassCleanup 属性的类。这些方法将运行一次针对每个单独的的TestClass 您的项目有。

您也可以使用 AssemblyInitialize AssemblyCleanup 属性来代替。只能有在任何给定组件这些方法之一,他们将分别运行的第一和最后一个,前和在任何类的任何测试方法后


更新:
AssemblyInitialize /清除需要在具有的TestClass 属性的类,但它并不重要哪一个。每个属性的单一的方法将之前或在装配运行的任何测试后得到执行。它不可能是一种测试方法,虽然;它必须是一个静态方法,并不能算作一个测试。

I am trying to implement AssemblyInitialize/AssemblyCleanup attributes in my Microsoft Visual Studio 2010 for the exact purpose as stated here. That link even describes the process which I need to follow to implement the code.

A quick summary of that purpose is to create an initial block of code which will run right before any test no matter which of the codedUITests I run in the solution and then a block of code which will run after the last codedUITest is completed. Example: I need to open up a specific application, then run a series of codedUITests which all start at that application and which are executed in any order, then close the application after everything is finished; this is more efficient than opening/closing the application for each codedUITest.

What I don't understand is where I need to place the code laid out at the bottom of that page (also shown below). I stuck all that code right under my 'public partial class UIMap' and the code runs except it runs the 'OpenApplication' and 'CloseApplication' commands before/after each CodedUITest instead of sandwiching the entire group of CodedUITests.

How do I implement the code correctly?

Update:

I discovered AssemblyI/C last night and I spent 3 hours trying to figure out where to put the code so it works. If I put the AssemblyInitialize at the beginning of a specific test method then:

1) It still wouldn't run - it was giving me some error saying that UIMap.OpenWindow() and UIMap.CloseWindow() methods need to be static and I couldn't figure out how to make them static.

2) Wouldn't the specific [TestMethod] which has the AssemblyI/C on it need to be in the test set? In my situation I have a dozen CodedUITests which need to run either individually or in a larger group and I need to get the AssemblyI/C to Open/Close the window I am testing.

解决方案

You've added the methods to the wrong class. By putting then into the UIMap partial class, you are telling the runtime to run those methods every time you create a new UIMap instance, which it sounds like you're doing every test.

The point of the ClassInitialize/ClassCleanup methods is to add them to the class with your test methods in it. You should have at least one class decorated with the TestClass attribute, which has at least one method decorated with a TestMethod attribute. This is the class that needs the ClassInitialize and ClassCleanup attributes applied to it. Those methods will run one time for each separate TestClass you have in your project.

You could also use the AssemblyInitialize and AssemblyCleanup attributes instead. There can only be one of these methods in any given assembly, and they will run first and last, respectively, before and after any test methods in any classes.


UPDATE: AssemblyInitialize/Cleanup need to be in a class that has the TestClass attribute, but it doesn't matter which one. The single method with each attribute will get run before or after any tests in the assembly run. It can't be a test method, though; it has to be a static method and will not count as a "test".

这篇关于如何实现AssemblyInitialize / AssemblyCleanup在我的codedUITest在2010年MSVS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆