Browsing projects by Tag(s)

Select a tag to browse associated projects and drill deeper into the tag cloud.

Showing page 1 of 2

PowerMock allows you to unit test code normally regarded as untestable. For instance it is possible to mock static methods, remove static initializers, allow mocking without dependency injection and more.

4.75
   
  0 reviews  |  13 users  |  42,220 lines of code  |  1 current contributor  |  Analyzed 7 days ago
 
 

Spock is a testing and specification framework for Java and Groovy developers. What makes it stand out from the crowd is its beautiful and highly expressive specification language. Thanks to its JUnit runner, Spock is compatible with most IDEs, build tools, and continuous integration servers. Spock ... [More] is inspired from JUnit, jMock, RSpec, Groovy, Scala, Vulcans, and other fascinating life forms. [Less]

4.5
   
  0 reviews  |  12 users  |  77,702 lines of code  |  7 current contributors  |  Analyzed 3 days ago
 
 

Provides method stubbing for concrete Java classes, intended for use with JUnit 4.

5.0
 
  0 reviews  |  1 user  |  5,641 lines of code  |  0 current contributors  |  Analyzed about 2 years ago
 
 

Mock4AS is a simple Mock Object Library for ActionScript3. The current version of Mock4AS provides a minimalistic Mock Objects library fulfilling the basic Unit Tests mocking needs. To get started download the latest version of Mock.as and add it to your project. What is Mock4AS?Mock4as is a ... [More] simple ActionScript3 library used to verify the interaction between dependent components. How to use Mock4asUsing a Mock4AS for unit testing involves the following steps: Create a mock object class 2 Instantiate a mock object 3 Create expectations for the mock 4 Inject the mock 5 Exercise the mock object 6 Verify the the mock expectations ExampleWe will use the Greeting example to illustrate the basic functionality of Mock4AS. The Greeting component says Hello in any language. Greeting uses a Translator component to translate “Hello” from English to the selected language. E.g. greeting.sayHello(“Portuguese”, “Paulo”) should return “Ola Paulo” ITranslator is an interface containing the translate method – parameters from, to and word, which returns the translated word; e.g translate(“English”, “Portuguese”, “Hello”) would return “Ola”. Greeting.as package org.mock4as.samples.greeting { public class Greeting { private var translator:ITranslator; public function Greeting(translator:ITranslator) { this.translator = translator; } public function sayHello(language:String, name:String):String { return translator.translate("English", language, "Hello") + " " + name; } } } ITranslator.as package org.mock4as.samples.greeting { public interface ITranslator { function translate(from:String, to:String, word:String):String; } }At construction time, the Greeting component receives a ITranslator component, a concrete implementation of the ITranslator interface. This simple mechanism is called Constructor Dependency Injection; basically an instance of the dependent component (some ITranslator implementation) is being injected in the Greeting component at construction time. 1. Declare the mockMock4AS offers two mechanisms to implement the mock behavior and verification: subclassing and composition. For clarity sake, the reminder of this page will introduce Mock4AS subclassing based mechanism. First, subclass org.mock4as.mock and implement the interface of the component you want to mock. You should have something similar to this: class MockTranslator extends Mock implements ITranslator {Next, set up the structure to record calls to the dependant component. For example, if you are making a mock object to replace a component that implements ISomeInterface, and ISomeInterace has a doSomething(stringArg:String):void method in it, your mock should now look something like this: public function translate(from:String, to:String, word:String):String { record("translate", from, to, word); return expectedReturnFor("translate"); }The record method call is what is needed to provide the mock implementation of the dependent component. MockTranslator code: import org.mock4as.Mock; import org.mock4as.samples.greeting.ITranslator; class MockTranslator extends Mock implements ITranslator { public function translate(from:String, to:String, word:String):String { record("translate", from, to, word); return expectedReturnFor("translate"); } }2. Create a mock objectYou create a mock the exactly same way you create any other object in AS3. var mock:MockTranslator = new MockTranslator();3. Create expectations for the mockIn order to verify that your mock has been invoked the way you expect, you first need to set up the expectation in the mock. You do this by evoking the mock API. The mock API provides the following methods for setting expectations: expects(methodName:String – Tells the mock the name of the expected method call times(numOfTimes:int) – Sets the number of times a particular method should be called withArgs(arg1, arg2, …argN) – Tells the mock what arguments should be passed to a particular method Example: To tell a mock to expect translate to be called with the arguments "English","Portuguese" and "Hello", and to return "Ola" you would write: mock.expects("translate").withArgs("English","Portuguese","Hello").willReturn("Ola"); 4. Inject the MockThe following code shows mock beinf injected during myGreeting construction time. var myGreeting:Greeting = new Greeting(mock);At construction time, the Greeting component receives mock, a concrete implementation of the ITranslator interface. The mock object which will record and verify expectations set against itself. 5. Exercise the mockYou need to exercise the component invoking he mock in order to verify the mock behavior and expectations. In our example, you need to exercise the Greeting component. assertEquals("Ola Paulo", myGreeting.sayHello("Portuguese", "Paulo"));6. Verify the the mock expectationsThe last step is to verify the mock expectations. assertTrue(mock.errorMessage(), mock.success());The success() method checks to see if the methods called match the expectations you have previously set. If mock is invoked the way we expected success() returns true. Otherwise success() will return false. The errorMessage() method returns a string that describes the reason why the verification failed. Some possible reasons for failure are: Methods were called that were not expected Methods were not called but they were expected An expected method was called but it was called with arguments that were not expected When the assertTrue(mock.errorMessage(), mock.success()) assertion fails, the test runner will output the string returned by mock.errorMessage() aiding in the effort to provide defect localization. The complete mock sample codeGreetingTest.as package org.mock4as.samples.greeting { import flexunit.framework.TestCase; import flexunit.framework.TestSuite; import org.mock4as.Mock; public class GreetingTest extends TestCase { public function GreetingTest(methodName : String){ super(methodName); } public function testGreetingInAnyLanguage():void{ // create the mock var mock:MockTranslator = new MockTranslator(); // set expectations mock.expects("translate").withArgs("English","Portuguese","Hello").willReturn("Ola"); // inject the mock var myGreeting:Greeting = new Greeting(mock); // execute and assert on greetign and assertEquals("Ola Paulo", myGreeting.sayHello("Portuguese", "Paulo")); // verify mock behavior assertTrue(mock.errorMessage(), mock.success()); } } } // Inner Class import org.mock4as.Mock; import org.mock4as.samples.greeting.ITranslator; class MockTranslator extends Mock implements ITranslator { public function translate(from:String, to:String, word:String):String { record("translate", from, to, word); return expectedReturnFor("translate"); } } [Less]

0
 
  0 reviews  |  0 users  |  1,229 lines of code  |  0 current contributors  |  Analyzed 10 days ago
 
 

A library for automatically creating mock objects in C++, setting expectations for calls on those objects and subsequently verifying that the expected calls were made.

0
 
  0 reviews  |  0 users  |  934 lines of code  |  0 current contributors  |  Analyzed about 8 hours ago
 
 

We are still working on making this library downloadable. For now, see Mock4AS, a simple implementation of a Mock Objects for AS3. IntroductionMockasin is a library that provides an easy way to use Mock Objects for given interfaces in AS3. Mock Objects simulate parts of the behavior of dependent ... [More] components, and are able to check whether they are used as defined. A Component can be tested in isolation by simulating its dependent components with Mock Objects. Mockasin BenefitsSupports refactoring-safe Mock Objects: test code will not break at runtime when renaming methods Supports return values and exceptions. Supports checking the order of method calls, for one or more Mock Objects. Mockasin Drawbacks (To Do List)Hand-writing classes for Mock Objects is needed. We are currently studying alternative solutions to remove the need for Hand-writing Mock classes. Mockasin by default supports the generation of Mock Objects for interfaces only. Alternative approaches are being considered for those who would like to generate Mock Objects for classes. UsageMost parts of a software system do not work in isolation, but collaborate with other parts to get their job done. In a lot of cases, we do not care about using collaborators in unit testing, as we trust these collaborators. If we do care about it, Mock Objects help us to test the unit under test in isolation. Mock Objects replace collaborators of the unit under test. ExampleWe will use the Greeting example to illustrate the basic functionality of Mockasin. The Greeting component says Hello in any language. Greeting uses a Translator component to translate “Hello” from English to the selected language. E.g. greeting.sayHello(“Portuguese”, “Paulo”) should return “Ola Paulo” ITranslator is an interface containing the translate method – parameters from, to and word, which returns the translated word; e.g translate(“English”, “Portuguese”, “Hello”) would return “Ola”. Greeting.as package com.google.mockasin.samples.greeting { public class Greeting { private var translator:ITranslator; public function Greeting(translator:ITranslator) { this.translator = translator; } public function sayHello(language:String, name:String):String { return translator.translate("English", language, "Hello") + " " + name; } } } ITranslator.as package com.google.mockasin.samples.greeting { public interface ITranslator { function translate(from:String, to:String, word:String):String; } }At construction time, the Greeting component receives a ITranslator component, a concrete implementation of the ITranslator interface. This simple mechanism is called CDI – Constructor Dependency Injection; basically an instance of the dependent component (some ITranslator implementation) is being injected in the Greeting component at construction time. The following examples assume that you are familiar with the FlexUnit testing framework. Although the tests shown here use FlexUnit in version 0.8.5, you may as well use !ASUnit (release 20071011). The First Mock ObjectWe will now build a test case for the Greeting component and understand the basic functionality of Mockasin. Our first test should check whether the greeting in any language returns the expected result, according to the ITranslator translated “Hello” word. Let’s follow the test code and analyze line by line. (The complete example of our first mock object is provided in the next section.) package com.google.mockasin.samples { import com.google.mockasin.*; public class GreetingTest extends TestCase { public function GreetingTest() { }The import statement makes the Mockasin functionality available for the current Unit Test code. Make sure your project do include the Mockasin library or source code. public override function setUp():void { reset(); }The reset() function should be called in between tests to make sure expectations of one test do not interfere with other tests. If the the reset() function is not invoked, expectations will be carried over. Please consider the reset() usage while designing your tests. public function testGreetingInAnyLanguage():void { // Create the mock. var mock:MockTranslator = new MockTranslator();An instance of MockTranslator is created. Mockasin gain control over MockTranslator instances by means of MockTranslator extending MockObject. // Set expectations. expect(mock.translate) .withArgs("English", "Swedish", "Hello") .andReturn("Hej");This is how you set expectations on the mock object. In this sample, you are telling Mockasin that translate("English", "Swedish", "Hello") should be invoked for your mock object and it should return "Hej" // Inject the mock. var myGreeting:Greeting = new Greeting(mock);The Greeting component receives concrete implementation of ITranslator interface as a constructor parameter. Mock is an instance of MockTranslator, which implements ITranslator. // Execute and assert on greeting. assertEquals("Hej Martin", myGreeting.sayHello("Swedish", "Martin")); Keep in mind that this test is for the Greeting component. This line is verifying the greeting functionality. // Verify mock behavior. verify(); } } }The verify() function will verify all expectations set for Mock Objects occurred as specified. In case of a failure, an error – with a meaningful message - is raised and your test will fail. // Inner Class import com.google.mockasin.MockObject; import com.google.mockasin.samples.greeting.ITranslator; class MockTranslator extends MockObject implements ITranslator { public function translate(from:String, to:String, word:String):String { return handleCall(arguments, this); } }You are required to create a MockTranslator class. In this example, MockTranslator was created as an Inner Class (on the same file) of GreetingTest.as The MockTranslator class must extend from MockObject and implement the ITranslator interface. The interface method implementation should contain return handleCall(arguments, this); Future releases of Mockasin will attempt to remove the need to create the MockTranslator class. The Completed Greeting Examplepackage com.google.mockasin.samples { import com.google.mockasin.*; public class GreetingTest extends TestCase { public function GreetingTest() { } public override function setUp():void { reset(); } public function testGreetingInAnyLanguage():void { // Create the mock. var mock:MockTranslator = new MockTranslator(); // Set expectations. expect(mock.translate) .withArgs("English", "Swedish", "Hello") .andReturn("Hej"); // Inject the mock. var myGreeting:Greeting = new Greeting(mock); // Execute and assert on greeting. assertEquals("Hej Martin", myGreeting.sayHello("Swedish", "Martin")); // Verify mock behavior. verify(); } } } // Inner class import com.google.mockasin.MockObject; import com.google.mockasin.samples.greeting.ITranslator; class MockTranslator extends MockObject implements ITranslator { public function translate(from:String, to:String, word:String):String { return handleCall(arguments, this); } } [Less]

0
 
  0 reviews  |  0 users  |  0 current contributors
 
 

NaturalSpec is a .NET UnitTest framework which provides automatically testable specs in natural language. NaturalSpec is based on NUnit and completely written in F# - but you don't have to learn F# to use it.

0
 
  0 reviews  |  0 users  |  41,329 lines of code  |  1 current contributor  |  Analyzed about 2 years ago
 
 

The Python dictionary-based mock memcached client library. It does not connect to any memcached server, but keeps a dictionary and stores every cache into there internally. It is a just emulated API of memcached client only for tests. It implements expiration also. NOT THREAD-SAFE.

0
 
  0 reviews  |  0 users  |  157 lines of code  |  0 current contributors  |  Analyzed 3 days ago
 
 
Compare

AMOP 0.3 is an Automatic Mock Object for C++. News: It works in GCC now...Please go to BuildInstructions Page to know more. By using ABI and template techniques, it can simulate a pseudo-"Reflection" which is normally not support in C++ . The main differences between AMOP and ... [More] other mock object library is that, users DO NOT need to implement the interface of the object which to mock... Please go to BasicUsage to know more. For any problem or feature requestion, you can leave a comment on GeneralDiscussion or go to amop google group. . [Less]

0
 
  0 reviews  |  0 users  |  17,482 lines of code  |  0 current contributors  |  Analyzed 3 days ago
 
 

A unit testing framework for C with mocking. cmocka only requires a test application is linked with the standard C library which minimizes conflicts with standard C library headers. It is the successor (fork) of cmockery.

0
 
  0 reviews  |  0 users  |  3,962 lines of code  |  2 current contributors  |  Analyzed 7 days ago
 
 
 
 

Creative Commons License Copyright © 2013 Black Duck Software, Inc. and its contributors, Some Rights Reserved. Unless otherwise marked, this work is licensed under a Creative Commons Attribution 3.0 Unported License . Ohloh ® and the Ohloh logo are trademarks of Black Duck Software, Inc. in the United States and/or other jurisdictions. All other trademarks are the property of their respective holders.