Skip to main content
Unfortunately, I wasn't able to deliver on the promise of more attention...
Source Link

In addition to @palacsint's advice, namely you should make the implicit dependencies of system under test explicit, I'll add a few more.

  • In my experience easiest way to make a business method that uses system time testable is to just pass the current time as a parameter. "Time" is not part of your domain after all. This refactoring is a form of Replace Static Variable with Parameter This will also save you the trouble of setting up a mock time provider service for test scenarios.

  • The following means org.RelatedOrganizationUnit is some kind of collection

    if (org.RelatedOrganizationUnit != null)
    {
       foreach (... in org.RelatedOrganizationUnit)
    

Make it default to an empty list, and you would not need to check for nulls. Less ifs, less test cases needed.

  • Factor out the repeating chunks about related organizations and EducationIndicator out smaller units are easier to test.

  • Duplication is bad in itself. The following two snippets look like they were copy/pasted; then an error was fixed, for just one copy.

    // this should throw NullReferenceException if org.UserArea is null
    if (!org.UserArea.Equals(null)) 
    
    if (org.UserArea != null)
    

I'll add a few more points when I've time...

In addition to @palacsint's advice, namely you should make the implicit dependencies of system under test explicit, I'll add a few more.

  • In my experience easiest way to make a business method that uses system time testable is to just pass the current time as a parameter. "Time" is not part of your domain after all. This refactoring is a form of Replace Static Variable with Parameter This will also save you the trouble of setting up a mock time provider service for test scenarios.

  • The following means org.RelatedOrganizationUnit is some kind of collection

    if (org.RelatedOrganizationUnit != null)
    {
       foreach (... in org.RelatedOrganizationUnit)
    

Make it default to an empty list, and you would not need to check for nulls. Less ifs, less test cases needed.

  • Factor out the repeating chunks about related organizations and EducationIndicator out smaller units are easier to test.

  • Duplication is bad in itself. The following two snippets look like they were copy/pasted; then an error was fixed, for just one copy.

    // this should throw NullReferenceException if org.UserArea is null
    if (!org.UserArea.Equals(null)) 
    
    if (org.UserArea != null)
    

I'll add a few more points when I've time...

In addition to @palacsint's advice, namely you should make the implicit dependencies of system under test explicit, I'll add a few more.

  • In my experience easiest way to make a business method that uses system time testable is to just pass the current time as a parameter. "Time" is not part of your domain after all. This refactoring is a form of Replace Static Variable with Parameter This will also save you the trouble of setting up a mock time provider service for test scenarios.

  • The following means org.RelatedOrganizationUnit is some kind of collection

    if (org.RelatedOrganizationUnit != null)
    {
       foreach (... in org.RelatedOrganizationUnit)
    

Make it default to an empty list, and you would not need to check for nulls. Less ifs, less test cases needed.

  • Factor out the repeating chunks about related organizations and EducationIndicator out smaller units are easier to test.

  • Duplication is bad in itself. The following two snippets look like they were copy/pasted; then an error was fixed, for just one copy.

    // this should throw NullReferenceException if org.UserArea is null
    if (!org.UserArea.Equals(null)) 
    
    if (org.UserArea != null)
    
added 455 characters in body
Source Link

In addition to @palacsint's advice, namely you should make the implicit dependencies of system under test explicit, I'll add a few more.

  • In my experience easiest way to make a business method that uses system time testable is to just pass the current time as a parameter. "Time" is not part of your domain after all. This refactoring is a form of Replace Static Variable with Parameter This will also save you the trouble of setting up a mock time provider service for test scenarios.

  • The following means org.RelatedOrganizationUnit is some kind of collection

    if (org.RelatedOrganizationUnit != null)
    {
       foreach (... in org.RelatedOrganizationUnit)
    

Make it default to an empty list, and you would not need to check for nulls. Less ifs, less test cases needed.

  • Factor out the repeating chunks about related organizations and EducationIndicator out smaller units are easier to test.

  • Duplication is bad in itself. The following two snippets look like they were copy/pasted; then an error was fixed, for just one copy.

    // this should throw NullReferenceException if org.UserArea is null
    if (!org.UserArea.Equals(null)) 
    
    if (org.UserArea != null)
    

I'll add a few more points when I've time...

In addition to @palacsint's advice, namely you should make the implicit dependencies of system under test explicit, I'll add a few more.

  • The following means org.RelatedOrganizationUnit is some kind of collection

    if (org.RelatedOrganizationUnit != null)
    {
       foreach (... in org.RelatedOrganizationUnit)
    

Make it default to an empty list, and you would not need to check for nulls. Less ifs, less test cases needed.

  • Factor out the repeating chunks about related organizations and EducationIndicator out smaller units are easier to test.

  • Duplication is bad in itself. The following two snippets look like they were copy/pasted; then an error was fixed, for just one copy.

    // this should throw NullReferenceException if org.UserArea is null
    if (!org.UserArea.Equals(null)) 
    
    if (org.UserArea != null)
    

I'll add a few more points when I've time...

In addition to @palacsint's advice, namely you should make the implicit dependencies of system under test explicit, I'll add a few more.

  • In my experience easiest way to make a business method that uses system time testable is to just pass the current time as a parameter. "Time" is not part of your domain after all. This refactoring is a form of Replace Static Variable with Parameter This will also save you the trouble of setting up a mock time provider service for test scenarios.

  • The following means org.RelatedOrganizationUnit is some kind of collection

    if (org.RelatedOrganizationUnit != null)
    {
       foreach (... in org.RelatedOrganizationUnit)
    

Make it default to an empty list, and you would not need to check for nulls. Less ifs, less test cases needed.

  • Factor out the repeating chunks about related organizations and EducationIndicator out smaller units are easier to test.

  • Duplication is bad in itself. The following two snippets look like they were copy/pasted; then an error was fixed, for just one copy.

    // this should throw NullReferenceException if org.UserArea is null
    if (!org.UserArea.Equals(null)) 
    
    if (org.UserArea != null)
    

I'll add a few more points when I've time...

Source Link

In addition to @palacsint's advice, namely you should make the implicit dependencies of system under test explicit, I'll add a few more.

  • The following means org.RelatedOrganizationUnit is some kind of collection

    if (org.RelatedOrganizationUnit != null)
    {
       foreach (... in org.RelatedOrganizationUnit)
    

Make it default to an empty list, and you would not need to check for nulls. Less ifs, less test cases needed.

  • Factor out the repeating chunks about related organizations and EducationIndicator out smaller units are easier to test.

  • Duplication is bad in itself. The following two snippets look like they were copy/pasted; then an error was fixed, for just one copy.

    // this should throw NullReferenceException if org.UserArea is null
    if (!org.UserArea.Equals(null)) 
    
    if (org.UserArea != null)
    

I'll add a few more points when I've time...