Developers have many different options out there to create fast and relatively maintainable unit test suites. But this takes a great deal of knowledge involved in decoupling modules of code, isolating the code under test within its test context, and using test doubles (stubs, fakes, mocks). What's more confusing is that within the conc...
I need to simulate a test scenario in which I call the getBytes() method of a String object and I get an UnsupportedEncodingException.
I have tried to achieve that using the following code:
String nonEncodedString = mock(String.class);
when(nonEncodedString.getBytes(anyString())).thenThrow(new UnsupportedEncodingException("Parsing erro...
I'm looking for a reliable mocking framework for ActionScript. I've been using mock-as3, but I'm annoyed with what I feel is a hack-ish solution for triggering events. There are other a few other reasons why I'd like to have some options, but not sure if I necessarily need to go into them. I've also looked into Mock4AS, but the interface...
I'd like to test an abstract class. Sure, I can manually write a mock that inherits from the class.
Can I do this using a mocking framework (I'm using Mockito) instead of hand-crafting my mock? How?
...
Are there any libraries or methods to mock out the file system in C# to write unit tests? In my current case I have methods that check whether certain file exists and read the creation date. I may need more than that in future.
...
Example
I have a repository class (DAL):
public class MyRepository : IMyRepository
{
public void Delete(int itemId)
{
// creates a concrete EF context class
// deletes the object by calling context.DeleteObject()
}
// other methods
}
I also have a service class (BLL):
public class MyService
{
pri...
It should parse EDMX file and create a moch/fake to use in Unit tests. The easiest integration would be by using T4 that we already have in VS IDE.
Has anybody seen it on the web?
Or is maybe writing it on their own?
Or is there an OSS in progress doing this?
Anybody?
...
Update:
Based on a couple of the answers I have received, I just want to make clear that I am well aware how to go about mocking HttpContext using a mocking framework. I am more interested knowing what the pros and cons of mocking HttpContext are when compared to using wrapper classes around HttpContext.
I'm looking for opinions on h...
The second assertion never executes in the unit test below:
namespace Foo {
public class MyClass {
}
}
namespace Bar {
public class MyClass {
}
}
namespace Quux {
public interface IRepo {
object Get<T>() where T : new();
}
}
namespace Tests {
[TestFixture]
public class MyTests {
private Mock<...
I'm wondering how to go about testing this. I have a method that takes a parameter, and based on some properties of that parameter it creates another object and operates on it. The code looks something like this:
- (void) navigate:(NavContext *)context {
Destination * dest = [[Destination alloc] initWithContext:context];
if (conte...
I am beginning to believe that unit testing high level, well-written code, which requires extensive use of mock objects, has little to no value. I am wondering if this assertion is correct, or am I missing something?
What do I mean by high level? These are the classes and functions near the top of the food chain. Their input and output ...
I have the following code for adding to/extracting from Zip. I'm trying to refactor this to make it test-ready. Can someone provide pointers on how I can accomplish this?
Aside: I'm using Moq as my mock framework and MSTest as my Unit Testing tool
private const long BufferSize = 4096;
public static void ExtractZip(string zipFilename...
Example:
public bool Save(MyObj instance)
{
if (instance.IsNew)
{
this.repository.Create(instance);
}
else
{
this.repository.Update(instance);
}
}
How do I create a test in Moq that verifies:
that a property IsNew is being read
that either Create() or Update() has been invoked
...
I'm looking for resources that provide an actual lesson plan or path to encourage and reinforce programming practices such as TDD and mocking. There are plenty of resources that show examples, but I'm looking for something that actually provides a progression that allows the concepts to be learned instead of forcing emulation.
My pri...
How would you test the following code?
public IList<T> Find(DetachedCriteria criteria)
{
return criteria.GetExecutableCriteria(session).List<T>();
}
I would like to mock NH implementation (like setting mocks for ISession, ISessionFactory etc.) but I am having trouble with this one.
...
I use NMock2, and I've drafted the following NMock classes to represent some common mock framework concepts:
Expect: this specifies what a mocked method should return and says that the call must occur or the test fails (when accompanied by a call to VerifyAllExpectationsHaveBeenMet()).
Stub: this specifies what a mocked method should r...
I am new to unit testing and mocking. I am trying to unit test an abstract domain class in Grails. How should I mock an implementation so I can unit test the constraints of the domain class? Is there a way to use the mock libraries that come with groovy or grails? Should I just implement a class that simply extends the abstract class?
...
Unit testing Abstract classes in Groovy
I asked a question previous about unit testing and mocking a domain class, but I do not think I was specific enough. I have a domain class:
package toplevel.domain
abstract class Party {
static hasMany = [roles:PartyRole]
static constraints = {
roles(nullable:true)
dateCr...
I'd really appreciate some advice around testing for errors using OCMock.
Method Under Test
It grabs a process using an instance of the AppScriptController class.
@implementation ProcessGrabber
-(void)grabProcess {
NSError *error = nil;
NSString *processName = [appScriptController processName:ProcessRef
...
How can i change the implementation of a method at runtime from return false; to return true;? I don't have control over the methods implementation as it comes with a third-party library. Any workaround is appreciated. Again: I do not control neither the method itself nor it's callers.
...