Title: Unit Testing something that returns nothing, how to assert?
Tags: c#;unit-testing
Question: How would you assert code like this? What would be the best approach to do so?
public void doSomething(int myProperty){
if (myProperty == 0) return;
// If myProperty is not zero, do something in the method

Here is the accepted answer: You could assert that whatever happens after the return doesn't happen when myProperty is zero.
For example, if the method is (pseudo code!)
if myProperty == 0 return
myOtherProperty = 2
then your unit test could
Arrange that myProperty is set to zero, myOtherProperty is set to something other than 2
Act by calling the method under test
Assert that myOtherProperty is still set to what it was set to before.
Comment for this answer: Hmm changed the code a bit to clarify the situation. But your reply did help me :] I could ofcourse assert that whatever happens after the if(), isn't set.

Here is another answer: I think Mark Seemann gave you complete answer - this is just an illustration to it.
SomeVerifiableClass actor;
public void doSomething(int myProperty){
if (myProperty == 0) return;
// If myProperty is not zero, do something in the method
actor.doesSomething(myProperty);
Then your choices are to mock SomeVerifiableClass or to test with real one. If you use DI properly then mocking is a better option.
Mocking: validating behavior (pseudo code):
verify(mockedActor).noMethodsCalled();
In case of real object you validate state:
assert(isPrestine(actor));
If there is no actor in your case then you should be able to verify state of tested object (the one that executes doSomething).
Comment for this answer: I'll have to go for that last one :] I'm used to test every bit of logic in the code and thus also test every if() explicitly. But since this if() doesn't return anything, I questioned myself how to approach this. But I could test that whenever the if() returns, objects after that if() don't change.

Here is another answer: If this code returns nothing, what is its purpose? What will be wrong if you remove this line?
If you find a valuable answer to these questions, you will find hints to test your code.
If you find no answer, then you can safely remove the line (and thus have no test to write).
Comment for this answer: The line's there to make sure the code won't continu if myProperty is 0, changed the question content a bit to clarify.
Comment for this answer: This was already clear for me. You've made a first step to design your test.
Comment for this answer: @AbhishekVelankar: Sanity checks return something when checks fail.
Comment for this answer: there could be functions for sanity checks. if your data pipeline can have such checks in early stages then you could save tone of processing time and resources.

Here is another answer: The question I ask when I see this is: what happens when myProperty is not zero?
Is there code after this return that alters class level/shared state? Can you assert against the class level/shared state to verify the behaviour?
When myProperty is zero, then the state should be unaffected by the method

Here is another answer: No matter what you do, you need to test against observable effects. Surely your method must be doing something.
When using state-based testing, you can inspect the state of your SUT or the Fixture after having executed the method to see if the state matches your expecations.
When that is not possible, you will need to perform Behavior Verification (aka interaction-based testing. This is often done with mock objects.

Here is another answer: You didn't post the method signature, so I suppose that it has void as return type. In this case there's no way to test it like you pointed; but if the method interacts with object scope properties you can test them to see if they change or not.

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 6, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 2.5', 'CreationDate': '2010:00:05/19/10', 'FavoriteCount': 0.0, 'PostTypeId': 1, 'Tags': '<c#><unit-testing>', 'Title': 'Unit Testing something that returns nothing, how to assert?', 'ViewCount': 4033, 'id': 2863746, 'user_AboutMe': '<p>Student @ Hanze University Groningen, studying information &amp; communication technology.</p>\n', 'user_AccountId': 120311.0, 'user_DisplayName': 'Bas', 'user_Reputation': 1222.0, 'user_Views': 118.0, 'user_id': 312670.0}}