"ERROR running force:source:deploy: INVALID_OPERATION: testLevel of NoTestRun cannot be used in production organizations" occurs
Last updated 3 days ago ·Reference W-8079014 ·Reported By 17 users
No Fix
Summary
"ERROR running force:source:deploy: INVALID_OPERATION: testLevel of NoTestRun cannot be used in production organizations" occurs although "RunLocalTests" is the default test level.
When deploying to a production instance, 'force:source:deploy -m ApexClass' you will receive an error 'INVALID_OPERATION: testLevel of NoTestRun cannot be used in production organizations'.
It should have a default testLevel of 'runLocalTests' for being a production org, but that isn't getting set.
Repro
1) Create a project.
* command: sfdx force:project:create -n MyProject --template standard
2) Move to class directory.
* command: cd MyProject/force-app/main/default/classes/
3) Create a simple Apex class
* command 1: sfdx force:apex:class:create -n confirmTestOption
* command 2: echo "public class confirmTestOption { public static Decimal FahrenheitToCelsius(Decimal fh) { Decimal cs = (fh - 32) * 5/9; return cs.setScale(2); }}" > confirmTestOption.cls
4) Create a simple Apex test class
* command 1: sfdx force:apex:class:create -n confirmTestOptionTest
* command 2: echo "@isTest private class confirmTestOptionTest { @isTest static void testWarmTemp() { Decimal celsius = confirmTestOption.FahrenheitToCelsius(70); System.assertEquals(21.11,celsius);}}" > confirmTestOptionTest.cls
5) Log into active org
* command: sfdx force:auth:web:login -r https://login.salesforce.com
6) Deploy Apex class and Apex test class.
* command: sfdx force:source:deploy -m ApexClass -u <Your User Name>
Following error occurs.
ERROR running force:source:deploy: INVALID_OPERATION: testLevel of NoTestRun cannot be used in production organizations
Workaround
To run the sfdx command through [TESTLEVEL] option.
Sample command: sfdx force:source:deploy -m ApexClass -u xxx@xxx.xxx -l RunLocalTests
Is it Fixed?
Any unreleased services, features, statuses, or dates referenced in this or other public statements are not currently available and may not be delivered on time or at all. Customers who purchase our services should make their purchase decisions based upon features that are currently available.
