Note that there are some explanatory texts on larger screens.

plurals
  1. POUnit Testing With Computer Owned States
    primarykey
    data
    text
    <p>I am writing a unit test for when my computer receives/makes a phone call.</p> <p>The methods being tested are the events that handle the incoming/outgoing call. If the caller is not an approved caller then the call is rejected.</p> <p>The code works fine, but I can't really find anything to test against for my unit test. The problem is that the actual state of "if my computer is in a call or not" is <strong>not</strong> controlled my by class. Only the computer knows if a call is currently connected or not.</p> <p>I am hoping that there are some Unit Test Guru's out there than can tell me what to do to test this scenario. I do not want to create a dummy var that has no relation to my code just to make my unit test pass.</p> <p>To make this a bit more concrete here is my unit test:</p> <pre><code> private DeviceMediator deviceMediator; private IDeviceControlForm deviceControlForm; private IDataAccess data; private ICallMonitor callMonitor; // Use TestInitialize to run code before running each test [TestInitialize()] public void MyTestInitialize() { deviceControlForm = MockRepository.GenerateStub&lt;IDeviceControlForm&gt;(); data = MockRepository.GenerateStub&lt;IDataAccess&gt;(); callMonitor = MockRepository.GenerateStub&lt;ICallMonitor&gt;(); deviceMediator = new DeviceMediator(deviceControlForm, data) {CallMonitor = callMonitor}; } [TestMethod] public void TestHandleIncomingCall() { //Arrange //Act deviceMediator.OnIncomingCall(null, new CallState(), new CallInfoState()); //Assert // I could not find anything to feasably test on this. Assert.IsTrue(true); } </code></pre> <p>and here is the method it is calling:</p> <pre><code>public void OnIncomingCall(Call call, CallState callState, CallInfoState callInfoState) { // See if this call is on our list of approved callers bool callApproved = false; foreach (PhoneContact phoneContact in Whitelist) { if (phoneContact.PhoneNumber == call.CallerID) callApproved = true; } // If this is not an approved call then if (!callApproved) CallMonitor.Hangup(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload