File Writing Testing Unit

I have a function that will take student data as input and write their report card to an xml file. When I tried to create unit tests in vs2008, I saw a message - "A method that does not return a value cannot be tested." My function does not return a value that it just writes to a file and returns.

How to write tests for this function?

[TestMethod()]
public void StoreInformationTest()
{
   StudentSettings target = new StudentSettings(); // TODO: Initialize to an appropriate   
   StudentSettings settings = null; // TODO: Initialize to an appropriate value
   target.StoreInformation(settings);
   Assert.Inconclusive("A method that does not return a value cannot be verified.");
}

Thanks in advance,

Regards, John

+3
source share
4 answers

- memystream. . . , , .

UPDATE:
. , StudentSettings . xml , . .

+2

, Visual Studio , , .

, , TextWriter . , , TextWriter.

+2

. Moq. , , . , , .

EDIT: , , , . moq , , . , /, , - .

+1
source

The code generator simply assumes that it cannot test your test based on its return value (void), which makes sense. I think someone else mentioned that this is more of a placeholder. When it comes to writing a test, you need to decide what your criteria for passing are. You can go as easy as:

Assert.IsTrue(File.Exists(filePath));

If all you care about is an existing file, or you can dive deeper into it, check its contents and so on. It really is up to you.

0
source

All Articles