Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C#: catch test failure during classcleanup

Is it possible to nest TestMethods in ClassCleanup and have them run/behave as TestMethods instead of regular method calls?

I have a TestClass to test an AppMngr class I created to manage a process. I test for the ability to Open/Close the app (e.g. MyNotepadMngrClass.Open() and ...Close()). I have several more classes that do work inside that process (e.g. MyNotepadWorkerClass.WriteLine() or ...DoSomething() ). When testing the other classes I need to start notepad and close it when done. ClassInitialize/ClassCleanup are obvious places for this. But I want to confirm notepad closed.

So I created a static [TestMethod] for the Close operation. I call it from ClassCleanup in MyNotepadWorkerTestClass. It performs the close operation fine. But if I add something like -- Assert.IsFalse(true); -- to the body of my close method the test run does not fail.

Let me know if what I am trying to do fundamentally wrong. Appreciate any you can give help.

P.S. Hey TestStand guys, I am looking for Setup/Ceanup behaviour during RunSelectedStep. TestDriven.NET gives me RunSelectedStep. So how do I catch failures during ClassInitialize and ClassCleanup.

like image 879
dFlat Avatar asked Dec 19 '10 01:12

dFlat


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

Is C language easy?

Compared to other languages—like Java, PHP, or C#—C is a relatively simple language to learn for anyone just starting to learn computer programming because of its limited number of keywords.

What is C in C language?

What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.


1 Answers

ClassCleanup is by definition to be used "after all the tests in the test class have run" (from msdn), so you probably can't add new test methods in there. You'll need to restructure your test.

like image 189
Tim Barrass Avatar answered Oct 05 '22 21:10

Tim Barrass