Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

C# unit test exception using attribrute

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void FromDirectoryIsNullOrEmpty()
        {
            var fromDir = "";
            Util_Directory.Copy(fromDir, "", false, false);

        }

       // the code method to test have this if condition
           if (string.IsNullOrEmpty(fromDir))
            {
                throw new ArgumentException($"'{nameof(fromDir)}' cannot be null or empty", nameof(fromDir));
            }
 
PREVIOUS NEXT
Tagged: #unit #test #exception #attribrute
ADD COMMENT
Topic
Name
7+6 =