testcase

How to escape double quotes in as a parameter to an NUnit TestCase?

百般思念 提交于 2019-11-28 09:36:12
I tried writing the following TestCase for an NUnit test written in VB.net: <TestCase("FirstNode", "<node id=\"FirstNode\">")> Public Sub GetNode_GivenSomeNodeId_ReturnCorrectNode(ByVal nodeId as String, ByVal expectedXml as String) (Call the method under test and request the xmlNode with the provided id...) Assert.AreEqual(expectedXml, returnedXml) End Sub The xml-node passed as the second parameter to the testcase is not valid however, as this clearly is not the correct way to escape double quotes. I'm sure I can find a workaround in order to check that the method under test returns the

Persist variable changes between tests in unittest?

混江龙づ霸主 提交于 2019-11-28 06:12:38
How do I persist changes made within the same object inheriting from TestCase in unitttest? from unittest import TestCase, main as unittest_main class TestSimpleFoo(TestCase): foo = 'bar' def setUp(self): pass def test_a(self): self.assertEqual(self.foo, 'bar') self.foo = 'can' def test_f(self): self.assertEqual(self.foo, 'can') if __name__ == '__main__': unittest_main() I.e.: I want those two tests above to pass As some comments have echoed, structuring your tests in this manner is probably a design flaw in the tests themselves and you should consider restructuring them. However, if you want

java.lang.NoClassDefFoundError:android and junit test

我怕爱的太早我们不能终老 提交于 2019-11-27 14:24:03
问题 I saw that I'm not the only one having this problem but I don't find a correct answer. I have an android project that I want to test. I create a junit test class for each class of my project. My problem is when I run my test, I have the following error : java.lang.NoClassDefFoundError: android/content/Context This is my class test : public class DevicesBDDTest extends TestCase { DevicesBDD bdd; /** * @throws java.lang.Exception */ protected static void setUpBeforeClass() throws Exception { }

How do I put new List<int> {1} in an NUNIT TestCase?

房东的猫 提交于 2019-11-27 13:31:04
问题 I have the method: public static int Add(List<int> numbers) { if (numbers == null || numbers.Count == 0) return 0; if (numbers.Count == 1) return numbers[0]; throw new NotImplementedException(); } Here is my test against it, but it does not like new List<int> {1} in the TestCase: [TestCase(new List<int>{1}, 1)] public void Add_WithOneNumber_ReturnsNumber(List<int> numbers) { var result = CalculatorLibrary.CalculatorFunctions.Add(numbers); Assert.AreEqual(1, result); } It gives me the error:

Test cases in inner classes with JUnit

六月ゝ 毕业季﹏ 提交于 2019-11-27 07:02:39
I read about Structuring Unit Tests with having a test class per class and an inner class per method. Figured that seemed like a handy way to organize the tests, so I tried it in our Java project. However, the tests in the inner classes doesn't seem to be picked up at all. I did it roughly like this: public class DogTests { public class BarkTests { @Test public void quietBark_IsAtLeastAudible() { } @Test public void loudBark_ScaresAveragePerson() { } } public class EatTests { @Test public void normalFood_IsEaten() { } @Test public void badFood_ThrowsFit() { } } } Does JUnit not support this,

How to escape double quotes in as a parameter to an NUnit TestCase?

对着背影说爱祢 提交于 2019-11-27 03:02:19
问题 I tried writing the following TestCase for an NUnit test written in VB.net: <TestCase("FirstNode", "<node id=\"FirstNode\">")> Public Sub GetNode_GivenSomeNodeId_ReturnCorrectNode(ByVal nodeId as String, ByVal expectedXml as String) (Call the method under test and request the xmlNode with the provided id...) Assert.AreEqual(expectedXml, returnedXml) End Sub The xml-node passed as the second parameter to the testcase is not valid however, as this clearly is not the correct way to escape double

Persist variable changes between tests in unittest?

纵饮孤独 提交于 2019-11-27 01:13:48
问题 How do I persist changes made within the same object inheriting from TestCase in unitttest? from unittest import TestCase, main as unittest_main class TestSimpleFoo(TestCase): foo = 'bar' def setUp(self): pass def test_a(self): self.assertEqual(self.foo, 'bar') self.foo = 'can' def test_f(self): self.assertEqual(self.foo, 'can') if __name__ == '__main__': unittest_main() I.e.: I want those two tests above to pass 回答1: As some comments have echoed, structuring your tests in this manner is

Test cases in inner classes with JUnit

我的梦境 提交于 2019-11-26 15:47:13
问题 I read about Structuring Unit Tests with having a test class per class and an inner class per method. Figured that seemed like a handy way to organize the tests, so I tried it in our Java project. However, the tests in the inner classes doesn't seem to be picked up at all. I did it roughly like this: public class DogTests { public class BarkTests { @Test public void quietBark_IsAtLeastAudible() { } @Test public void loudBark_ScaresAveragePerson() { } } public class EatTests { @Test public

Does MSTest have an equivalent to NUnit&#39;s TestCase?

给你一囗甜甜゛ 提交于 2019-11-26 07:29:40
问题 I find the TestCase feature in NUnit quite useful as a quick way to specify test parameters without needing a separate method for each test. Is there anything similar in MSTest? [TestFixture] public class StringFormatUtilsTest { [TestCase(\"tttt\", \"\")] [TestCase(\"\", \"\")] [TestCase(\"t3a4b5\", \"345\")] [TestCase(\"3&amp;5*\", \"35\")] [TestCase(\"123\", \"123\")] public void StripNonNumeric(string before, string expected) { string actual = FormatUtils.StripNonNumeric(before); Assert