Skip to main content
deleted 30 characters in body
Source Link
Robert Harvey
  • 200.7k
  • 55
  • 470
  • 683

Edit1:

Edit2: Approach ##Approach 2

Edit3: Conclusion ##Conclusion

Edit1:

Edit2: Approach 2

Edit3: Conclusion

##Approach 2

##Conclusion

added conclusion
Source Link
Devesh
  • 445
  • 1
  • 5
  • 16

Edit3: Conclusion


If redesigning of SUT is possible:
  1. There should ideally be no out parameter instead an aggregate class should be evaluated in Asserts.
  2. If there are unrelated out parameters then SUT method should be refactored into multiple methods, then those new methods should have their own Test methods and they will then test only one concern.

If redesigning of SUT is not possible then as per the answer there will be three Asserts

Edit3: Conclusion


If redesigning of SUT is possible:
  1. There should ideally be no out parameter instead an aggregate class should be evaluated in Asserts.
  2. If there are unrelated out parameters then SUT method should be refactored into multiple methods, then those new methods should have their own Test methods and they will then test only one concern.

If redesigning of SUT is not possible then as per the answer there will be three Asserts

added new approach for unit Testing
Source Link
Devesh
  • 445
  • 1
  • 5
  • 16

Edit2: Approach 2


Seperate Test methods that tests concerns separately:
    public void DosSomething_Passing15_Returns12Test(){
        //add code for arrange
        int expectedvalue=12;
        string expectedVariable1="I am expected";
        string expectedVariable3=15.9;
        string actualVariable1, actualVariable3;
        var sut=new Foo();
        int actualValue=sut.DoSomething(15, out actualVariable1, out actualVariable3);
        
        Assert.IsTrue(actualValue, expectedvalue);
    }
    
    public void DosSomething_Passing15_ReturnsExpectedVariable1Test(){
        //add code for arrange
        int expectedvalue=12;
        string expectedVariable1="I am expected";
        string expectedVariable3=15.9;
        string actualVariable1, actualVariable3;
        var sut=new Foo();
        int actualValue=sut.DoSomething(15, out actualVariable1, out actualVariable3);
        
        Assert.IsTrue(actualVariable1, expectedVariable1);
    }
    
    public void DosSomething_Passing15_ReturnsExpectedVariable2Test(){
        //add code for arrange
        int expectedvalue=12;
        string expectedVariable1="I am expected";
        string expectedVariable3=15.9;
        string actualVariable1, actualVariable3;
        var sut=new Foo();
        int actualValue=sut.DoSomething(15, out actualVariable1, out actualVariable3);
        
        Assert.IsTrue(actualVariable3, expectedVariable3);
    }

Isn't approach 2 adhering to "Tests should not test more than one concern"?

Edit2: Approach 2


Seperate Test methods that tests concerns separately:
    public void DosSomething_Passing15_Returns12Test(){
        //add code for arrange
        int expectedvalue=12;
        string expectedVariable1="I am expected";
        string expectedVariable3=15.9;
        string actualVariable1, actualVariable3;
        var sut=new Foo();
        int actualValue=sut.DoSomething(15, out actualVariable1, out actualVariable3);
        
        Assert.IsTrue(actualValue, expectedvalue);
    }
    
    public void DosSomething_Passing15_ReturnsExpectedVariable1Test(){
        //add code for arrange
        int expectedvalue=12;
        string expectedVariable1="I am expected";
        string expectedVariable3=15.9;
        string actualVariable1, actualVariable3;
        var sut=new Foo();
        int actualValue=sut.DoSomething(15, out actualVariable1, out actualVariable3);
        
        Assert.IsTrue(actualVariable1, expectedVariable1);
    }
    
    public void DosSomething_Passing15_ReturnsExpectedVariable2Test(){
        //add code for arrange
        int expectedvalue=12;
        string expectedVariable1="I am expected";
        string expectedVariable3=15.9;
        string actualVariable1, actualVariable3;
        var sut=new Foo();
        int actualValue=sut.DoSomething(15, out actualVariable1, out actualVariable3);
        
        Assert.IsTrue(actualVariable3, expectedVariable3);
    }

Isn't approach 2 adhering to "Tests should not test more than one concern"?

Tweeted twitter.com/#!/StackProgrammer/status/450271099188944896
elaborated question with example
Source Link
Devesh
  • 445
  • 1
  • 5
  • 16
Loading
Source Link
Devesh
  • 445
  • 1
  • 5
  • 16
Loading