npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fflib-auto-test

v1.0.5-beta

Published

Create quick test skeletons for Apex methods written with fflib framework.

Downloads

18

Readme

FFLIB AUTO TEST

A simple CLI to create a test method skeleton for passed methods that were written with the https://github.com/apex-enterprise-patterns/fflib-apex-common & https://github.com/apex-enterprise-patterns/fflib-apex-mocks framework.

Assumptions

The naming convention of the class names for which this tool was developed follows the ProjectName_ObjectPlural_ClassType pattern. So, for example Rovms_Users_SRV where Rovms is the project name, Users the plural of the User object and SRV denoting the fact that the class in question is a service class. Selector classes are detected when suffixed with _SEL and Domain classes when suffixed with _DOM.

If you are using a different naming convention, please raise a PR or let me know about it and we'll add it as a configuration possibility. This is very much still a first beta version.

Example

In order to produce a test method skeleton for the method randomMethod in class Rovms_Opportunities_SRV:

public class Rovms_Users_SRV {
	public static IService newInstance() {
		return (Rovms_Users_SRV) Rovms_Application_UTIL.service.newInstance(Rovms_Users_SRV.class);
	}

	public interface IService {
		void randomMethod(Set<Id> userIds);
	}

	public void randomMethod(Set<Id> userIds) {
		fflib_ISObjectUnitOfWork uow = Rovms_Application_UTIL.unitOfWork.newInstance();

		List<User> users = Rovms_Users_SEL.newInstance().selectByIds(userIds);

		List<Contact> contacts = Rovms_Contacts_SEL.newInstance().selectBest100();
		Rovms_Contacts_DOM.newInstance(contacts).assignBestContacts(uow, users);

		Map<String, User> firstNameToUser = Rovms_Users_DOM.newInstance(users).getFirstNameToUser();
		Rovms_Users_SRV.newInstance().refresh(firstNameToUser);

		uow.commitWork();
	}
}

Running:

fflib-auto-test examples/Rovms_Opportunities_SRV.cls randomMethod

produces something like:

@isTest
private static void randomMethod_test() {
// Set up mocks
fflib_ApexMocks mocks = new fflib_ApexMocks();
fflib_ISObjectUnitOfWork uowMock = new fflib_SObjectMocks.SObjectUnitOfWork(mocks);
Rovms_Users_SEL userSelectorMock = (Rovms_Users_SEL) mocks.mock(Rovms_Users_SEL.class);
Rovms_Contacts_SEL contactSelectorMock = (Rovms_Contacts_SEL) mocks.mock(Rovms_Contacts_SEL.class);

// Given
// -- SETUP DATA (MOCKED) HERE --


// Set Mocks
mocks.startStubbing();
mocks.when(userSelectorMock.sObjectType()).thenReturn(User.getSObjectType());
mocks.when(userSelectorMock.selectByIds(-- ARGS --)).thenReturn(-- RET ARGS --);
mocks.when(contactSelectorMock.sObjectType()).thenReturn(Contact.getSObjectType());
mocks.when(contactSelectorMock.selectBest100(-- ARGS --)).thenReturn(-- RET ARGS --);
mocks.when(contactDomainMock.sObjectType()).thenReturn(Contact.getSObjectType());
mocks.when(contactDomainMock.assignBestContacts(-- ARGS --)).thenReturn(-- RET ARGS --);
mocks.when(userDomainMock.sObjectType()).thenReturn(User.getSObjectType());
mocks.when(userDomainMock.getFirstNameToUser(-- ARGS --)).thenReturn(-- RET ARGS --);
mocks.when(userServiceMock.sObjectType()).thenReturn(User.getSObjectType());
mocks.when(userServiceMock.refresh(-- ARGS --)).thenReturn(-- RET ARGS --);
mocks.stopStubbing();

Rovms_Application_UTIL.selector.setMock(userSelectorMock);
Rovms_Application_UTIL.selector.setMock(contactSelectorMock);
Rovms_Application_UTIL.domain.setMock(contactDomainMock);
Rovms_Application_UTIL.domain.setMock(userDomainMock);
Rovms_Application_UTIL.service.setMock(Rovms_Users_SRV.class, userServiceMock);

// When
Rovms_Users_SRV.newInstance().randomMethod(-- ARGS --);

// Then
//-- VERIFY TEST RESULTS --

}

This part is output in the console and can be copy-pasted into the desired test class.

Mock data, method arguments and test assertions have to be done manually (for now).