使用NUnit进行单元测试

编程入门 行业动态 更新时间:2024-10-16 22:13:05
本文介绍了使用NUnit进行单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用NUnit框架进行单元测试。 我的问题是在NUnit中我收到错误MolopolyGame.Testing._Card.TestConstructor: 没有提供任何参数 我正在测试的方法返回一个数组中的随机项。 我有一个方法需要测试

I am using the NUnit framework for unit testing. My question is that in NUnit I am getting the error "MolopolyGame.Testing._Card.TestConstructor: No arguments were provided" The method which i am testing returns a random item in an array. I have a method which i need to test

public string GetCommunityCard() { //generate random community card int card; Random randomCommunityCard = new Random(); card = randomCommunityCard.Next(communityChestCardArray.Length); return communityChestCardArray[card]; }

这是我到目前为止为该方法编写的测试

and this is the test that I have written so far for the method

namespace MolopolyGame.Testing { [TestFixture] public class _Card { [Test] public void TestConstructor(string retArray) { Card Card = new Card(); string myCard = Card.GetCommunityCard(); Assert.AreEqual(myCard, retArray); } } }

我不太确定我做错了什么? 谢谢

I am not too sure what I am doing wrong? Thank you

推荐答案

return communityChestCardArray [card] .ToString()需要在实际方法中添加。 return communityChestCardArray[card].ToString() needs to be added in the actual method.

更多推荐

使用NUnit进行单元测试

本文发布于:2023-11-06 23:57:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1565008.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:单元测试   NUnit

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!