Better test names

I have some simple tests written, however, the names are not good…I think, any suggestions on better names? I’m not really sure how these tests should be named. I’m looking for a format or pattern I can follow. [TestClass] public class DoorTests { [TestMethod] public void DoorIsNotVirtualIfNameStartsWithLetterOtherThanV() { var door = new Door {Name = … Read more

Bad form for JUnit test to throw exception?

I’m pretty new to JUnit, and I don’t really know what best practices are for exceptions and exception handling. For example, let’s say I’m writing tests for an IPAddress class. It has a constructor IPAddress(String addr) that will throw an InvalidIPAddressException if addr is null. As far as I can tell from googling around, the … Read more

Using Basic HTTP access authentication in Django testing framework

For some of my Django views I’ve created a decorator that performs Basic HTTP access authentication. However, while writing test cases in Django, it took me a while to work out how to authenticate to the view. Here’s how I did it. I hope somebody finds this useful. Answer Here’s how I did it: from … Read more

Test a specific exception type is thrown AND the exception has the right properties

I want to test that MyException is thrown in a certain case. EXPECT_THROW is good here. But I also want to check the exception has a specific state e.g e.msg() == “Cucumber overflow”. How is this best implemented in GTest? Answer A colleague came up with the solution by just re-throwing the exception. The knack: … Read more

Why DbContext doesn’t implement IDbContext interface?

Why there is no IDbContext interface in the Entity Framework? Wouldn’t it be easier to test things if there was an existing interface with methods like SaveChanges() etc. from which you could derive your custom database context interface? public interface ICustomDbContext : IDbContext { // add entity set properties to existing set of methods in … Read more

How are people unit testing code that uses Linq to SQL [closed]

Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 6 months ago. Improve this question How are people unit testing code that uses Linq to SQL? Answer Update: Fredrik has … Read more

xUnit or NUnit? What advantages and disadvantages of each other? [duplicate]

This question already has answers here: NUnit vs. MbUnit vs. MSTest vs. xUnit.net [closed] (7 answers) Closed 8 years ago. What are the pluses and minuses of each framework, comparing to each other? How well they work with ASP.NET MVC? How well they support mocking? Answer I work with NUnit only. It is pretty good … Read more

PHPUnit Mock Objects and Static Methods

I am looking for the best way to go about testing the following static method (specifically using a Doctrine Model): class Model_User extends Doctrine_Record { public static function create($userData) { $newUser = new self(); $newUser->fromArray($userData); $newUser->save(); } } Ideally, I would use a mock object to ensure that fromArray (with the supplied user data) and … Read more