Create unit test cases for a method that returns no value in C #

Possible duplicate:
Single validation methods?

I need to write unit test cases for GUI methods that do not return any value, how can I check ac

+1
source share
3 answers

You can make sure it doesn't throw away at least

Assert.DoesNotThrow<ExceptionType>( () => myClass.myMethod() ); 

However, keep in mind that a method that does not return a value but does something relies on side effects and, therefore, is not amenable to unit testing, since you cannot test the entire state of the system in unit test.

+3
source

You can make fun of the specific methods and classes that your method calls and claims to be called. For this purpose, you can use some mocking frameworks, most of which have functionality for testing: Assert.IsCalled ();

You can also argue that certain changes in the environment that are expected are being implemented. For example, a file is created.

+2
source

If it does not throw an exception when passing the correct values ​​for the parameters (if any), then it passes. If it throws the correct exceptions when passing invalid values, it passes.

+1
source

Source: https://habr.com/ru/post/919878/


All Articles