As some of you will know, it is generally not possible to mock a static method in .net.
By mocking, I mean to replace a method in a class with another method with the same signature, usually for testing purposes.
The two main methods used for mocking a method are to declare it virtual or define it in an interface. Neither of these two...
I am toying around to learn how to unit test ASP.NET MVC controller actions. Specifically I'm trying to mock the ControllerContext so that I can test an action that accesses HttpContext.Current.User.Identity.Name.
I'm using Moq.
Things were going pretty well until I turned on MockBehavior.Strict. I knew that this would throw an excep...
Hi.
I am using Cucumber as the BDD framework with rspec/mocha mocking. Ideally we would not mock/stub behavior in cucumber specs; however the scenario is exceptional here. To give you the brief idea of problem here; I have two features product feature and cart feature.
Cart feature is currently mocking some of the product fetch from 3 ...
I'm trying to create a mock object of \SplObserver using PHPunit and attach the mocked object to an \SplSubject. When I try to attach the mocked object to a class that implements \SplSubject, I get a catchable fatal error saying that the mocked object doesn't implement \SplObserver:
PHP Catchable fatal error: Argument 1 passed to ..\A...
What's the best method to test a custom form builder? Is there a test ActiveRecord class/object in Rails' test suite that i could use, or do i have to create my own mock-class? Which AR behavior do i have to 'emulate'?
...
hey guys
I'm new to mocking, and I'm having a hard time solving an issue with UnitTesting.
Say I have this code:
public class myClass{
private IDoStuff _doer;
public myClass(IDoStuff doer){
_doer = doer;
}
public void Go(SomeClass object){
//do some crazy stuff to the object
_doer.DoStuff(o...
I'm trying to write some tests with PHPUnit for our various classes/methods/functions. Some of these require database connectivity. Obviously, I'd like to Mock these, so that I don't change our database(s).
Can someone point me to some code that explains how to do this? I see lots of examples of Mocking, but nothing specifically abou...
I am new to mocking so I might have it totally wrong here but I believe that most mocking frameworks are interface dependent. Unfortunately most of our code is not using an interface. Now the other day I saw a Mocking framework in Java that reproduced the byte code of a class\object as to not call its internal methods but you could still...
In-container testing is often opposed to testing with mock objects. However, as mock objects simply mimic the behavior of the real objects, isn't the in-container testing the only way to really test the system in its' real environment?
As an partial alternative to in-container testing and mock objects, Spring provides the TestContext fr...
I have a Java 6 based web service client using the standard Java 6 annotation based approach (i.e. no Axis or other third party web service library), which works very well. So does the web service I am calling, which is nice, but now I need to write error handling code, and I need to be able to make the existing web service unreliable i...
Hi,
I would like to test a method from an abstract class. In this class is there a abstract method with is static.
I use PHPUnit. With normal abstract methods it works:
<?php
abstract class AbstractClass
{
public function concreteMethod()
{
return $this->abstractMethod();
}
public abstract function abstractMethod();
}
cl...
Sometimes in my code, I'll check to see if a particular object implements an interface:
if ($instance instanceof Interface) {};
However, creating mocks of said interface in PHPUnit, I can't seem to pass that test.
// class name is Mock_Interface_431469d7, does not pass above check
$instance = $this->getMock('Interface');
I under...
I have a scenario more or less like this
class A
def initialize(&block)
b = B.new(&block)
end
end
I am unit testing class A and I want to know if B#new is receiving the block passed to A#new. I am using Mocha as mock framework.
Is it possible?
...
Hello,
What is the simplest way to make mock json services?
Is there any program for that like there is for soap?
Thanks
...
Say I have an interface that has as property another interface. Something like:
interface IOne
{
ITwo Two { get; set;}
}
And I create a mock for ITwo and then create a mock for IOne using Mock<ITwo>.Object. How can I raise an event on ITwo when I only have a reference to IOne or Mock<IOne>? I need a reference for Mock<ITw...
I've got a method that's mildly complicated and needs to be very well tested. Secret sauce stuff. Ok, maybe not that cool, but I'm not 100% sure how to go about getting these things setup. This sort of stems from my previous question here. I haven't used rhino mocks so I'm still bad/unaware of the syntax, so feel free to make a ton o...
I'm writing unit tests. And I cannot test one function, because it calls keyWindow
UIWindow* window = [UIApplication sharedApplication].keyWindow;
And keyWindow returns nil (I don't have any window).
But I need to return anything, but nil.
I used category to manually set keyWindow value, but this didn't work
@interface UIApplication...
Hi,
I can't find a solution to mock ControllerContext.ParentActionViewContext.
here is the code of my controller
[ChildActionOnly]
public ViewResult Menu()
{
string controller = ControllerContext.ParentActionViewContext.RouteData.Values["controller"].ToString();
string action = ControllerContext.ParentActionViewContext.RouteData.Values...
Does anyone have experience in using a .NET mocking framework for medical device software?
I'm currently considering both Moq and Rhino Mocks and was hoping for some insight on their usage under FDA and EU requirements and possibly some resources on validation performed for either of them.
Thanks!
...
Hi,
I am coding some unit tests and wondered, is it in the duty of Typemock to replace paremeters?
For example, I have a method which relies on an object and in this object's constructor are some assemblies to analyze (a string array).
Would I be on the right track to mock the class containing the method and then pass in my own parame...