Skip to content

rbauction/metamate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

metamate

Salesforce metadata management tool

The tool is currently only capable of verifying a deployment package by deploying it with [checkOnly] (https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_deploy.htm) parameter set to true and running a subset of tests. This is done to speed up testing step in the CI workflow (run a subset of tests instead of all tests).

The tool uses [sfdclib Python library] (https://github.com/rbauction/sfdclib) to manipulate Salesforce metadata.

Names of the Apex classes that get tested are extracted from the deployment package.

  • If deployment package contains a test class it will be added to the list of classes to test.
  • For non-test classes the tool will build a dependency map for all test classes it can find in the source directory and then check whether any non-test classes from the deployment package are referenced by test classes. If there is a match the corresponding test class(es) will be added to the list of classes to test.

Example

Deployment package contents
  • RealClass
  • UnrealClass
  • TestableClassTest
Source directory contents (classes directory)
  • RealClass
  • RealClassTest (references RealClass)
  • UnrealClass
  • TestableClass
  • TestableClassTest (references TestableClass)
Classes to be tested
  • RealClassTest
  • TestableClassTest

Installation

Linux, UNIX and Mac OS

Install Python v3.4, PyYAML package, install [sfdclib Python library] (https://github.com/rbauction/sfdclib) and clone this repository.

pip install PyYAML
pip install sfdclib
git clone https://github.com/rbauction/metamate.git

Windows

Download executable file from [releases] (https://github.com/rbauction/metamate/releases) tab or follow the instruction above.

How to create Windows executable

Install PyInstaller and then run the following command:

pyinstaller metamate.spec

Resulting exe file can be found in dist directory.

Usage

metamate.py deploy [-h] --username USERNAME --password PASSWORD [--token TOKEN]
            --deploy-zip DEPLOY_ZIP --source-dir SOURCE_DIR
            [--sandbox] [--check-only] [--use-cache] [--version VERSION]
or
metamate.py clear-cache --username USERNAME
Deploy a deployment package (ZIP file) (Windows, Linux, UNIX and Mac OS)
# Validate deployment package (Windows, Linux, UNIX and Mac OS)
python metamate.py deploy --check-only --sandbox --username [email protected] --password Password --deploy-zip ../deploy.zip

# Deploy using default Metadata API version (Windows, Linux, UNIX and Mac OS)
python metamate.py deploy --sandbox --username [email protected] --password Password --deploy-zip ../deploy.zip

# Specify Metadata API version and token (Windows, Linux, UNIX and Mac OS)
python metamate.py deploy --sandbox --version 37.0 --username [email protected] --password Password --token TOKEN --deploy-zip ../deploy.zip

# Deploy using default Metadata API version (Windows only)
metamate.exe deploy --sandbox --username [email protected] --password Password --deploy-zip ..\deploy.zip
Run unit tests contained in a deployment package (ZIP file) (Windows, Linux, UNIX and Mac OS)
# Compile all test classes to resolve dependencies
python metamate.py deploy --check-only --test-level RunSpecifiedTests --sandbox --username [email protected] --password Password --deploy-zip ../deploy.zip --source-dir ../src

# Use local cache and compile only changed test classes (cache will be populated for each sandbox first time the tool is run)
python metamate.py deploy --use-cache --check-only --test-level RunSpecifiedTests --sandbox --username [email protected] --password Password --deploy-zip ../deploy.zip --source-dir ../src
Clear local cache
python metamate.py clear-cache --username [email protected]