本文介绍了我如何测试小数的金额?谢谢。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 使用系统; 使用 System.Text; 使用 System.Collections.Generic; 使用 Microsoft.VisualStudio.TestTools.UnitTesting; 使用 MyClassLibrary; 命名空间 InvoiceTest { /// /// tstInvoice $的摘要说明b $ b /// [TestClass] public class tstInvoice { public tstInvoice() { // // TODO:在此处添加构造函数逻辑 // } #region其他测试属性 // // 在编写测试时,您可以使用以下附加属性: // // 使用ClassInitialize在类中运行第一个测试之前运行代码 // [ClassInitialize()] // public static void MyClassInitialize(TestContext testContext ){} // // 使用ClassCleanup在类中的所有测试运行后运行代码 // [ClassCleanup()] // pub lic static void MyClassCleanup(){} // // 使用TestInitialize在运行每个测试之前运行代码 // [TestInitialize()] // public void MyTestInitialize(){} // // 在每次测试运行后使用TestCleanup运行代码 // [TestCleanup()] // public void MyTestCleanup(){} // #endregion [TestMethod] public void InstanceOK() { // 创建我们要创建的类的实例 clsInvoice AInvoice = new clsInvoice(); // 测试是否存在 Assert.IsNotNull(AInvoice) ; } [TestMethod] public void AddressProperty() { // 创建我们要创建的类的实例 clsInvoice AInvoice = new clsInvoice(); // 创建一些测试数据以分配给属性 string SomeAddress = 莱斯特郡; // 将数据分配给属性 AInvoice.Address = SomeAddress; // 测试以查看两个值是否相同 Assert。 AreEqual(AInvoice.Address,SomeAddress); } [TestMethod] public void AddressNoPropertyOK() { // 创建我们要创建的类的实例 clsInvoice AInvoice = new clsInvoice(); // 创建一些测试数据以分配给属性 Int32 AddressNo = 1 ; // 将数据分配给属性 AInvoice.AddressNo = AddressNo; // 测试以查看两个值是否相同 Assert。 AreEqual(AInvoice.AddressNo,AddressNo); } [TestMethod] public void ValidMethodOK() { // 创建我们要创建的类的实例 clsInvoice AInvoice = new clsInvoice(); // 用于存储验证结果的布尔变量 布尔 OK = false ; // 创建一些测试数据以分配给属性 string SomeAddress = 莱斯特郡; // 调用方法 OK = AInvoice.Valid(SomeAddress); // 测试以查看结果是否正确 Assert.IsTrue(好); } [TestMethod] public void AddressMinLessOne() { // 创建我们要创建的类的实例 clsInvoice AInvoice = new clsInvoice(); // 用于存储验证结果的布尔变量 布尔 OK = false ; // 创建一些测试数据以分配给属性 string SomeAddress = ; // 调用方法 OK = AInvoice.Valid(SomeAddress); // 测试以查看结果是否正确 Assert.IsFalse(好); } [TestMethod] public void AddressMinBoundary() { // 创建我们要创建的类的实例 clsInvoice AInvoice = new clsInvoice(); // 用于存储验证结果的布尔变量 布尔 OK = false ; // 创建一些测试数据以分配给属性 string SomeAddress = a; // 调用方法 OK = AInvoice.Valid(SomeAddress); // 测试以查看结果是否正确 Assert.IsTrue(好); } [TestMethod] public void AddressMinPlusOne() { // 创建我们要创建的类的实例 clsInvoice AInvoice = new clsInvoice(); // 用于存储验证结果的布尔变量 布尔 OK = false ; // 创建一些测试数据以分配给属性 string SomeAddress = aa; // 调用方法 OK = AInvoice.Valid(SomeAddress); // 测试以查看结果是否正确 Assert.IsTrue(好); } [TestMethod] public void AddressMaxLessOne() { // 创建我们要创建的类的实例 clsInvoice AInvoice = new clsInvoice(); // 用于存储验证结果的布尔变量 布尔 OK = false ; // 创建一些测试数据以分配给属性 string SomeAddress = abcdefghijabcdefghijabcdefghijabcdefghij; // 调用方法 OK = AInvoice.Valid(SomeAddress); // 测试以查看结果是否正确 Assert.IsTrue(好); } [TestMethod] public void AddressMaxBoundary() { // 创建我们要创建的类的实例 clsInvoice AInvoice = new clsInvoice(); // 用于存储验证结果的布尔变量 布尔 OK = false ; // 创建一些测试数据以分配给属性 string SomeAddress = abcdefghijabcdefghijabcdefghijabcdefghijabcdefghij; // 调用方法 OK = AInvoice.Valid(SomeAddress); // 测试以查看结果是否正确 Assert.IsTrue(好); } [TestMethod] public void AddressMaxPlusOne() { // 创建我们要创建的类的实例 clsInvoice AInvoice = new clsInvoice(); // 用于存储验证结果的布尔变量 布尔 OK = false ; // 创建一些测试数据以分配给属性 string SomeAddress = abcdefghijabcdefghijabcdefghijabcdefghijabcdefghija; // 调用方法 OK = AInvoice.Valid(SomeAddress); // 测试以查看结果是否正确 Assert.IsFalse(好); } [TestMethod] public void AddressMid() { // 创建我们要创建的类的实例 clsInvoice AInvoice = new clsInvoice(); // 用于存储验证结果的布尔变量 布尔 OK = false ; // 创建一些测试数据以分配给属性 string SomeAddress = abcdefghijabcdefghijabcde; // 调用方法 OK = AInvoice.Valid(SomeAddress); // 测试以查看结果是否正确 Assert.IsTrue(好); } [TestMethod] public void AddressExtremeMax() { // 创建我们要创建的类的实例 clsInvoice AInvoice = new clsInvoice(); // 用于存储验证结果的布尔变量 布尔 OK = false ; // 创建一些测试数据以分配给属性 string SomeAddress = ; // 用字符填充字符串 SomeAddress = SomeAddress.PadRight( 500 ,' a'); // 调用方法 OK = AInvoice.Valid(SomeAddress); // 测试以查看结果是否正确 Assert.IsFalse(好); } [TestMethod] public void ActivePropertyOK() { // 创建我们要创建的类的实例 clsInvoice AInvoice = new clsInvoice(); // 用于存储验证结果的布尔变量 布尔 TestData = true ; // 将数据分配给属性 AInvoice.Active = TestData; // 测试以查看两个值是否相同 Assert。 AreEqual(AInvoice.Active,TestData); } [TestMethod] public void InvoiceDateOK() { // 创建我们要创建的类的实例 clsInvoice AInvoice = new clsInvoice(); // 创建一些测试数据以分配给属性 DateTime TestData = DateTime.Now.Date; // 将数据分配给属性 AInvoice.DateAdded = TestData; // 测试以查看两个值是否相同 Assert。 AreEqual(AInvoice.DateAdded,TestData); } [TestMethod] public void DateAddedPropertyOK() { // 创建我们要创建的类的实例 clsInvoice AInvoice = new clsInvoice(); // 创建一些测试数据以分配给属性 DateTime TestData = DateTime.Now.Date; // 将数据分配给属性 AInvoice.DateAdded = TestData; // 测试以查看两个值是否相同 Assert。 AreEqual(AInvoice.DateAdded,TestData); } [TestMethod] public void AddressOK() { // 创建我们要创建的类的实例 clsInvoice AInvoice = new clsInvoice(); // 创建一些测试数据以分配给属性 string TestData = 某些地址; // 将数据分配给属性 AInvoice.Address = TestData; // 测试以查看两个值是否相同 Assert。 AreEqual(AInvoice.Address,TestData); } [TestMethod] public void AmountOK() { // 创建我们要创建的类的实例 clsInvoice AInvoice = new clsInvoice(); // 创建一些测试数据以分配给属性 decimal TestData = 3.2; // 将数据分配给属性 AInvoice.Amount = TestData; // 测试以查看两个值是否相同 Assert。 AreEqual(AInvoice.Amount,TestData); } } } 我尝试过: 我如何测试 ' 金额', a ' 十进制?'谢谢。 我是什么尝试过: 我如何测试小数是多少?谢谢。解决方案 decimal TestData = 3 .2M; using System; using System.Text; using System.Collections.Generic; using Microsoft.VisualStudio.TestTools.UnitTesting; using MyClassLibrary; namespace InvoiceTest { /// /// Summary description for tstInvoice /// [TestClass] public class tstInvoice { public tstInvoice() { // // TODO: Add constructor logic here // } #region Additional test attributes // // You can use the following additional attributes as you write your tests: // // Use ClassInitialize to run code before running the first test in the class // [ClassInitialize()] // public static void MyClassInitialize(TestContext testContext) { } // // Use ClassCleanup to run code after all tests in a class have run // [ClassCleanup()] // public static void MyClassCleanup() { } // // Use TestInitialize to run code before running each test // [TestInitialize()] // public void MyTestInitialize() { } // // Use TestCleanup to run code after each test has run // [TestCleanup()] // public void MyTestCleanup() { } // #endregion [TestMethod] public void InstanceOK() { //create an instance of the class we want to create clsInvoice AInvoice = new clsInvoice(); //test to see that it exists Assert.IsNotNull(AInvoice); } [TestMethod] public void AddressProperty() { //create an instance of the class we want to create clsInvoice AInvoice = new clsInvoice(); //create some test data to assign to the property string SomeAddress = "Leicestershire"; //assign the data to the property AInvoice.Address = SomeAddress; //test to see that the two values are the same Assert.AreEqual(AInvoice.Address, SomeAddress); } [TestMethod] public void AddressNoPropertyOK() { //create an instance of the class we want to create clsInvoice AInvoice = new clsInvoice(); //create some test data to assign to the property Int32 AddressNo = 1; //assign the data to the property AInvoice.AddressNo = AddressNo; //test to see that the two values are the same Assert.AreEqual(AInvoice.AddressNo, AddressNo); } [TestMethod] public void ValidMethodOK() { //create an instance of the class we want to create clsInvoice AInvoice = new clsInvoice(); //boolean variable to store the result of the validation Boolean OK = false; //create some test data to assign to the property string SomeAddress = "Leicestershire"; //invoke the method OK = AInvoice.Valid(SomeAddress); //test to see that the result is correct Assert.IsTrue(OK); } [TestMethod] public void AddressMinLessOne() { //create an instance of the class we want to create clsInvoice AInvoice = new clsInvoice(); //boolean variable to store the result of the validation Boolean OK = false; //create some test data to assign to the property string SomeAddress = ""; //invoke the method OK = AInvoice.Valid(SomeAddress); //test to see that the result is correct Assert.IsFalse(OK); } [TestMethod] public void AddressMinBoundary() { //create an instance of the class we want to create clsInvoice AInvoice = new clsInvoice(); //boolean variable to store the result of the validation Boolean OK = false; //create some test data to assign to the property string SomeAddress = "a"; //invoke the method OK = AInvoice.Valid(SomeAddress); //test to see that the result is correct Assert.IsTrue(OK); } [TestMethod] public void AddressMinPlusOne() { //create an instance of the class we want to create clsInvoice AInvoice = new clsInvoice(); //boolean variable to store the result of the validation Boolean OK = false; //create some test data to assign to the property string SomeAddress = "aa"; //invoke the method OK = AInvoice.Valid(SomeAddress); //test to see that the result is correct Assert.IsTrue(OK); } [TestMethod] public void AddressMaxLessOne() { //create an instance of the class we want to create clsInvoice AInvoice = new clsInvoice(); //boolean variable to store the result of the validation Boolean OK = false; //create some test data to assign to the property string SomeAddress = "abcdefghijabcdefghijabcdefghijabcdefghij"; //invoke the method OK = AInvoice.Valid(SomeAddress); //test to see that the result is correct Assert.IsTrue(OK); } [TestMethod] public void AddressMaxBoundary() { //create an instance of the class we want to create clsInvoice AInvoice = new clsInvoice(); //boolean variable to store the result of the validation Boolean OK = false; //create some test data to assign to the property string SomeAddress = "abcdefghijabcdefghijabcdefghijabcdefghijabcdefghij"; //invoke the method OK = AInvoice.Valid(SomeAddress); //test to see that the result is correct Assert.IsTrue(OK); } [TestMethod] public void AddressMaxPlusOne() { //create an instance of the class we want to create clsInvoice AInvoice = new clsInvoice(); //boolean variable to store the result of the validation Boolean OK = false; //create some test data to assign to the property string SomeAddress = "abcdefghijabcdefghijabcdefghijabcdefghijabcdefghija"; //invoke the method OK = AInvoice.Valid(SomeAddress); //test to see that the result is correct Assert.IsFalse(OK); } [TestMethod] public void AddressMid() { //create an instance of the class we want to create clsInvoice AInvoice = new clsInvoice(); //boolean variable to store the result of the validation Boolean OK = false; //create some test data to assign to the property string SomeAddress = "abcdefghijabcdefghijabcde"; //invoke the method OK = AInvoice.Valid(SomeAddress); //test to see that the result is correct Assert.IsTrue(OK); } [TestMethod] public void AddressExtremeMax() { //create an instance of the class we want to create clsInvoice AInvoice = new clsInvoice(); //boolean variable to store the result of the validation Boolean OK = false; //create some test data to assign to the property string SomeAddress = ""; //pad the string with a character SomeAddress = SomeAddress.PadRight(500, 'a'); //invoke the method OK = AInvoice.Valid(SomeAddress); //test to see that the result is correct Assert.IsFalse(OK); } [TestMethod] public void ActivePropertyOK() { //create an instance of the class we want to create clsInvoice AInvoice = new clsInvoice(); //boolean variable to store the result of the validation Boolean TestData = true; //assign the data to the property AInvoice.Active = TestData; //test to see that the two values are the same Assert.AreEqual(AInvoice.Active, TestData); } [TestMethod] public void InvoiceDateOK() { //create an instance of the class we want to create clsInvoice AInvoice = new clsInvoice(); //create some test data to assign to the property DateTime TestData = DateTime.Now.Date; //assign the data to the property AInvoice.DateAdded = TestData; //test to see that the two values are the same Assert.AreEqual(AInvoice.DateAdded, TestData); } [TestMethod] public void DateAddedPropertyOK() { //create an instance of the class we want to create clsInvoice AInvoice = new clsInvoice(); //create some test data to assign to the property DateTime TestData = DateTime.Now.Date; //assign the data to the property AInvoice.DateAdded = TestData; //test to see that the two values are the same Assert.AreEqual(AInvoice.DateAdded, TestData); } [TestMethod] public void AddressOK() { //create an instance of the class we want to create clsInvoice AInvoice = new clsInvoice(); //create some test data to assign to the property string TestData = "Some Address"; //assign the data to the property AInvoice.Address = TestData; //test to see that the two values are the same Assert.AreEqual(AInvoice.Address, TestData); } [TestMethod] public void AmountOK() { //create an instance of the class we want to create clsInvoice AInvoice = new clsInvoice(); //create some test data to assign to the property decimal TestData = "3.2"; //assign the data to the property AInvoice.Amount = TestData; //test to see that the two values are the same Assert.AreEqual(AInvoice.Amount, TestData); } } }What I have tried: How would i test 'Amount' which is a 'Decimal?' Thanks.What I have tried:how do i test amount which is a decimal? Thanks. 解决方案 decimal TestData = 3.2M; 这篇关于我如何测试小数的金额?谢谢。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-13 14:59