How to Display The Description of my Unit Test on TeamCity WebUI? - unit-testing

I'm using NUnit and TeamCity and I have written some system tests with descriptions.
/// <summary>
/// Should send the password reminder and...
/// </summary>
[Test]
public void ShouldSendPasswordReminder()
{
}
On Teamcity, after a test has run, it displays only the Status, Test Method Name, Test Class Name and Duration; however, I'd like to have the "Description" of the test to be displayed on the TeamCity WebUI as well.
How would that be possible?
Thanks,

I would consider making the name of the unit test method self descriptive, as described by Roy Osherove:
http://osherove.com/blog/2005/4/3/naming-standards-for-unit-tests.html
This is also described in his book,The Art of Unit Testing, here:
http://artofunittesting.com/

Related

Visual Studio 2013: Creating ordered tests

Can someone suggest a way to run tests in a specific order in Visual Studio 2013 Express?
Is there a way to create a playlist for the tests, which also defines the order in which to run them?
By the way: These are functional tests, using Selenium, written as unit tests in C#/Visual Studio. Not actual unit tests. Sometimes a regression test suite is so big it takes a while to run through all the tests. In these cases, I've often seen the need to run the test in a prioritized order. Or, there can be cases where it's difficult to run some tests without some other tests having been run before. In this regard, it's a bit more complicated than straight unit tests (which is the reason why it's normally done by test professionals, while unit tests are done by developers).
I've organised the tests in classes with related test methods. Ex.: All login tests are in a class called LoginTests, etc.
Class LoginTests:
- AdminCanLogin (...)
- UserCanLogin (...)
- IncorrectLoginFails (...)
- ...
CreatePostTests
- CanCreateEmptyPost (...)
- CanCreateBasicPost (...)
...
These classes are unit test classes, in their own project. They in turn calls classes and methods in a class library that uses Selenium.
MS suggests creating an "Ordered Unit Test" project. However, this is not available in the Express edition.
To address your playlist request directly see MS article: http://msdn.microsoft.com/en-us/library/hh270865.aspx Resharper also has a nice test play list tool as well.
Here is an article on how to setup Ordered Tests but you cannot use this feature with Express as it requires Visual Studio Ultimate, Visual Studio Premium, Visual Studio Test Professional. http://msdn.microsoft.com/en-us/library/ms182631.aspx
If you need them ordered then they are more then likely integration tests. I am assuming you would like them ordered so you can either prepare data for the test or tear data back down after the test.
There are several ways to accommodate this requirement if it is the case. Using MSTest there are 4 attributes for this you can see more details of when they are executed here http://blogs.msdn.com/b/nnaderi/archive/2007/02/17/explaining-execution-order.aspx.
My other suggestion would be to have a helper class to preform the tasks(not tests) you are looking to have done in order, to be clear this class would not be a test class just a normal class with common functionality that would be called from within your tests.
If you need a test to create a product so another test can use that product and test that it can be added to a shopping cart then I would create a "SetupProduct" method that would do this for you as I am sure you would be testing various things that would require a product. This would prevent you from having test dependencies.
With that said, integration tests are good to verify end to end processes but where possible and applicable it might be easier to mock some or all dependencies such as your repositories. I use the Moq framework and find it really easy to work with.
This code is from the blog post linked above, I am placing it here in case the link ever dies.
Here is an example of a test class using the setup / tear down attributes to help with your tests.
[TestClass]
public class VSTSClass1
{
private TestContext testContextInstance;
public TestContext TestContext
{
get
{
return testContextInstance;
}
set
{
testContextInstance = value;
}
}
[ClassInitialize]
public static void ClassSetup(TestContext a)
{
Console.WriteLine("Class Setup");
}
[TestInitialize]
public void TestInit()
{
Console.WriteLine("Test Init");
}
[TestMethod]
public void Test1()
{
Console.WriteLine("Test1");
}
[TestMethod]
public void Test2()
{
Console.WriteLine("Test2");
}
[TestMethod]
public void Test3()
{
Console.WriteLine("Test3");
}
[TestCleanup]
public void TestCleanUp()
{
Console.WriteLine("TestCleanUp");
}
[ClassCleanup]
public static void ClassCleanUp()
{
Console.WriteLine("ClassCleanUp");
}
}
Here is the order that the methods were fired.
Class Setup
Test Init
Test1
TestCleanUp
Test Init
Test2
TestCleanUp
Test Init
Test3
TestCleanUp
ClassCleanUp
If you give more information on what you are trying to accomplish I would be happy to assist you in when to use which attribute or when to use the help class, note the helper class is NOT a test class just a standard class that has methods you can utilize to do common tasks that may be needed for multiple tests.

mvn test does not find JUnit Tests

I have a a test class which is named xxxTest.java so the test class if found. But the unit tests within the class are not run when I execute mvn test.
I am using JUnit 4 and the test method's are annotated with #Test. eg.
#Test
public void shouldDoSomeAsserting() {
// unit test impl
}
If I rename that test method so it is name testShouldDoSomeAsserting() then mvn test does find and execute that unit test.
I was under the impression that when I use #Test as long as the method was public and void that it would be considered a test method.
Have I missed something?
Thanks.
Are you absolutely sure you are using JUnit 4? This sounds like JUnit 3 behaviour.
I made a minimal sample project and I couldn't recreate your problem. The test runs as expected.
The sample project is here: https://gist.github.com/1888802
Maybe you can get some kind of hint from it.
I've got it working by manually specifying a provider; more details here: Surefire JUnit 4 config

using IProvideDynamicTestMethods for silverlight 4 unit tests

Has anyone had any lucking creating their custom test class and using the IProvideDynamicTestMethods interface? I have a case where I need to dynamically generate test methods and this seems to be what I need. I goal is to have test methods generated based on some files I am testing.
Jeff Wilcox mentions this as a new feature in SL3 ( http://www.jeff.wilcox.name/2008/09/rc0-new-test-features/ , see the dynamic test methods section), but I was unable to find any examples of this.
I don't know how to register my custom test class (it inherits from ITestClass). I looked at the SL4 unit testing source to see how the test class are discovered and I found the following in UnitTestFrameworkAssembly.cs source link
/// <summary>
/// Reflect and retrieve the test class metadata wrappers for
/// the test assembly.
/// </summary>
/// <returns>Returns a collection of test class metadata
/// interface objects.</returns>
public ICollection<ITestClass> GetTestClasses()
{
ICollection<Type> classes = ReflectionUtility.GetTypesWithAttribute(_assembly, ProviderAttributes.TestClass);
List<ITestClass> tests = new List<ITestClass>(classes.Count);
foreach (Type type in classes)
{
tests.Add(new TestClass(this, type));
}
return tests;
}
It looks like it will always use the built-in TestClass.
Am I missing something? I don't how to get the test framework to use my custom TestClass
Any pointers appreciated.
Thanks
It looks like the only way to set this up right now is to write your own UnitTestProvider for the test runner. The good thing is the code is available, so it's not too hard to do this.
You can either grab the code from the default Vstt from codeplex here and make any changes you you like to it. I'm still experimenting with this right now, so lets see how this goes. I got this idea by looking at this github project.
The key was to plug in your own provider, which was done in Raven.Tests.Silverlight.UnitTestProvider.Example/App.xaml.cs.
Hope this helps someone

Is there a way to unit test a HttpEvent based servlet?

I have a Comet Servlet which has been coded using Jboss Advanced IO techniques, trhough the usage of HttpEventServlet interface.
Are there any frameworks that can be used to unit test such a code? So far, I have tried jUnit and HttpUnit with no sucess. My google search didn't return any positive results for this question as well.
I would like to invoke the event method in my unit tests
/**
* Process the given event.
*
*/
public void event(HttpEvent event) { ... }

How to output log in MS Unit Testing Framework VS 2010

I am trying to log some information while the unit test is running in MS Unit Testing Framework VS 2010.
I tried Trace.WriteLine, Console.WriteLine and Debug.WriteLine but I am not able to see the output in the output window.
Any idea how to do it? Thanks in advance
Make sure your test class contains the following:
private TestContext testContextInstance;
/// <summary>
/// Gets or sets the test context which provides
/// information about and functionality for the current test run.
/// </summary>
public TestContext TestContext
{
get
{
return testContextInstance;
}
set
{
testContextInstance = value;
}
}
Then you can call:
this.testContextInstance.WriteLine("Hello World");
The output from the test case is not visible in visual studio's output window. Rather it is visible in the "test results window". In the test result window, you should double click on the result of the test case (Passed/addTest row in the picture) for which you want to see the output and there you will see the all your writeLines.