Skip to content

some bad code - #2

Open
codefriar wants to merge 1 commit into
masterfrom
feature/kpoorman/badcode
Open

some bad code#2
codefriar wants to merge 1 commit into
masterfrom
feature/kpoorman/badcode

Conversation

@codefriar

Copy link
Copy Markdown
Collaborator

No description provided.

@codefriar codefriar left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a basic note

Comment thread SimplyBadCode.cls
@@ -0,0 +1,8 @@
class SimplyBadCode {
public static void loopExample(){

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you see developers using this method? Does it make sense to keep it static? would an instance method make sense coupled with a static wrapper?

We tend to strive away from static methods, if only because A,B,C.

Comment thread SimplyBadCode.cls
public static void loopExample(){
for(Integer i = 0; i <500; i++){
Contact c = new Contact(name='name '+i);
insert c;

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

R: When we do DML in a for loop, the platform may trigger Governor limits. <>

We expect code in our codebase to persist lists of information outside of the for loop.

List<Contact> contacts = new List<Contact>();
for(Integer i=0; i<500; i++){
....
}
insert contacts;

Comment thread PA_Tests.cls
@isTest
private class PartnerAgreement_test {

@testsetup static void createTestData(){

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love the way we encourage the use of @testsetup methods! Good job.

Comment thread PA_Tests.cls
//PrdColors test input
test.starttest();


Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this is the result of a bad branch merge?
When we write tests, we want to make sure that we're asserting the resulting values to ensure the code is working as we expect.
Before we can merge this, we need to address the lack of assertions.

Comment thread PA_Tests.cls
test.stoptest();

}
@isTest static void test_CMDT_Coverage(){

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want our unit test method names to be very descriptive of what they do! we'll need to refactor this before merge so that we can quickly identify what we expected and what failed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant