Best junit code snippet using junit.framework.TestCase.fail
Source:5990.java
...
Source:TestRunListenerTest3.java
...65 String source=66 "package pack;\n" +67 "import junit.framework.TestCase;\n" +68 "public class ATestCase extends TestCase {\n" +69 " public void testFail() { fail(); }\n" +70 "}";71 IType aTestCase= createType(source, "pack", "ATestCase.java");72 String[] expectedSequence= new String[] {73 "sessionStarted-" + TestRunListeners.sessionAsString("ATestCase", ProgressState.RUNNING, Result.UNDEFINED, 0),74 "testCaseStarted-" + TestRunListeners.testCaseAsString("testFail", "pack.ATestCase", ProgressState.RUNNING, Result.UNDEFINED, null, 0),75 "testCaseFinished-" + TestRunListeners.testCaseAsString("testFail", "pack.ATestCase", ProgressState.COMPLETED, Result.FAILURE, new FailureTrace("junit.framework.AssertionFailedError", null, null), 0),76 "sessionFinished-" + TestRunListeners.sessionAsString("ATestCase", ProgressState.COMPLETED, Result.FAILURE, 0)77 };78 String[] actual= runSequenceTest(aTestCase);79 assertEqualLog(expectedSequence, actual);80 }81 public void testSimpleTest() throws Exception {82 String source=83 "package pack;\n" +84 "import junit.framework.*;\n" +85 "\n" +86 "public class ATestCase extends TestCase {\n" +87 " protected int fValue1;\n" +88 " protected int fValue2;\n" +89 "\n" +90 " public ATestCase(String name) {\n" +91 " super(name);\n" +92 " }\n" +93 " protected void setUp() {\n" +94 " fValue1= 2;\n" +95 " fValue2= 3;\n" +96 " }\n" +97 " public static Test suite() {\n" +98 " // ensure ordering:\n" +99 " TestSuite result= new TestSuite(\"ATestCase\");\n" +100 " result.addTest(new ATestCase(\"testAdd\"));\n" +101 " result.addTest(new ATestCase(\"testDivideByZero\"));\n" +102 " result.addTest(new ATestCase(\"testEquals\"));\n" +103 " return result;\n" +104 " }\n" +105 " public void testAdd() {\n" +106 " double result= fValue1 + fValue2;\n" +107 " // forced failure result == 5\n" +108 " assertTrue(result == 6);\n" +109 " }\n" +110 " public void testDivideByZero() {\n" +111 " int zero= 0;\n" +112 " int result= 8/zero;\n" +113 " }\n" +114 " public void testEquals() {\n" +115 " assertEquals(12, 12);\n" +116 " assertEquals(12L, 12L);\n" +117 " assertEquals(new Long(12), new Long(12));\n" +118 "\n" +119 " assertEquals(\"Size\", String.valueOf(12), String.valueOf(13));\n" +120 " }\n" +121 " public static void main (String[] args) {\n" +122 " junit.textui.TestRunner.run(suite());\n" +123 " }\n" +124 "}";125 IType aTestCase= createType(source, "pack", "ATestCase.java");126 String[] expectedSequence= new String[] {127 "sessionStarted-" + TestRunListeners.sessionAsString("ATestCase", ProgressState.RUNNING, Result.UNDEFINED, 0),128 "testCaseStarted-" + TestRunListeners.testCaseAsString("testAdd", "pack.ATestCase", ProgressState.RUNNING, Result.UNDEFINED, null, 0),129 "testCaseFinished-" + TestRunListeners.testCaseAsString("testAdd", "pack.ATestCase", ProgressState.COMPLETED, Result.FAILURE, new FailureTrace("junit.framework.AssertionFailedError", null, null), 0),130 "testCaseStarted-" + TestRunListeners.testCaseAsString("testDivideByZero", "pack.ATestCase", ProgressState.RUNNING, Result.UNDEFINED, null, 0),131 "testCaseFinished-" + TestRunListeners.testCaseAsString("testDivideByZero", "pack.ATestCase", ProgressState.COMPLETED, Result.ERROR, new FailureTrace("java.lang.ArithmeticException", null, null), 0),132 "testCaseStarted-" + TestRunListeners.testCaseAsString("testEquals", "pack.ATestCase", ProgressState.RUNNING, Result.UNDEFINED, null, 0),133 "testCaseFinished-" + TestRunListeners.testCaseAsString("testEquals", "pack.ATestCase", ProgressState.COMPLETED, Result.FAILURE, new FailureTrace("junit.framework.ComparisonFailure", "12", "13"), 0),134 "sessionFinished-" + TestRunListeners.sessionAsString("ATestCase", ProgressState.COMPLETED, Result.ERROR, 0)135 };136 String[] actual= runSequenceTest(aTestCase);137 assertEqualLog(expectedSequence, actual);138 }139 public void testTreeOnSessionStarted() throws Exception {140 String source=141 "package pack;\n" +142 "import junit.framework.TestCase;\n" +143 "public class ATestCase extends TestCase {\n" +144 " public void testSucceed() { }\n" +145 "}";146 IType aTestCase= createType(source, "pack", "ATestCase.java");147 String[] expectedTree= new String[] {148 TestRunListeners.sessionAsString("ATestCase", ProgressState.RUNNING, Result.UNDEFINED, 0),149 TestRunListeners.suiteAsString("pack.ATestCase", ProgressState.NOT_STARTED, Result.UNDEFINED, null, 1),150 TestRunListeners.testCaseAsString("testSucceed", "pack.ATestCase", ProgressState.NOT_STARTED, Result.UNDEFINED, null, 2),151 };152 String[] actual= runTreeTest(aTestCase, 1);153 assertEqualLog(expectedTree, actual);154 }155 public void testTreeOnSessionEnded() throws Exception {156 String source=157 "package pack;\n" +158 "import junit.framework.TestCase;\n" +159 "public class ATestCase extends TestCase {\n" +160 " public void testFail() { fail(); }\n" +161 "}";162 IType aTestCase= createType(source, "pack", "ATestCase.java");163 String[] expectedTree= new String[] {164 TestRunListeners.sessionAsString("ATestCase", ProgressState.COMPLETED, Result.FAILURE, 0),165 TestRunListeners.suiteAsString("pack.ATestCase", ProgressState.COMPLETED, Result.FAILURE, null, 1),166 TestRunListeners.testCaseAsString("testFail", "pack.ATestCase", ProgressState.COMPLETED, Result.FAILURE, new FailureTrace("junit.framework.AssertionFailedError", null, null), 2),167 };168 String[] actual= runTreeTest(aTestCase, 4);169 assertEqualLog(expectedTree, actual);170 }171 public void testTreeOnSecondTestStarted() throws Exception {172 String source=173 "package pack;\n" +174 "import junit.framework.*;\n" +175 "public class ATestCase extends TestCase {\n" +176 " public static Test suite() {\n" +177 " // ensure ordering:\n" +178 " TestSuite result= new TestSuite(\"pack.ATestCase\");\n" +179 " result.addTest(new ATestCase(\"testSucceed\"));\n" +180 " result.addTest(new ATestCase(\"testFail\"));\n" +181 " return result;\n" +182 " }\n" +183 " public ATestCase(String name) {\n" +184 " super(name);\n" +185 " }\n" +186 " public void testSucceed() { }\n" +187 " public void testFail() { fail(); }\n" +188 "}";189 IType aTestCase= createType(source, "pack", "ATestCase.java");190 String[] expectedTree= new String[] {191 TestRunListeners.sessionAsString("ATestCase", ProgressState.RUNNING, Result.UNDEFINED, 0),192 TestRunListeners.suiteAsString("pack.ATestCase", ProgressState.RUNNING, Result.UNDEFINED, null, 1),193 TestRunListeners.testCaseAsString("testSucceed", "pack.ATestCase", ProgressState.COMPLETED, Result.OK, null, 2),194 TestRunListeners.testCaseAsString("testFail", "pack.ATestCase", ProgressState.RUNNING, Result.UNDEFINED, null, 2),195 };196 String[] actual= runTreeTest(aTestCase, 4);197 assertEqualLog(expectedTree, actual);198 }199 public void testTreeOnSecondTestStarted2() throws Exception {200 String source=201 "package pack;\n" +202 "import junit.framework.*;\n" +203 "public class ATestCase extends TestCase {\n" +204 " public static Test suite() {\n" +205 " // ensure ordering:\n" +206 " TestSuite result= new TestSuite(\"pack.ATestCase\");\n" +207 " result.addTest(new ATestCase(\"testFail\"));\n" +208 " result.addTest(new ATestCase(\"testSucceed\"));\n" +209 " return result;\n" +210 " }\n" +211 " public ATestCase(String name) {\n" +212 " super(name);\n" +213 " }\n" +214 " public void testFail() { fail(); }\n" +215 " public void testSucceed() { }\n" +216 "}";217 IType aTestCase= createType(source, "pack", "ATestCase.java");218 String[] expectedTree= new String[] {219 TestRunListeners.sessionAsString("ATestCase", ProgressState.RUNNING, Result.FAILURE, 0),220 TestRunListeners.suiteAsString("pack.ATestCase", ProgressState.RUNNING, Result.FAILURE, null, 1),221 TestRunListeners.testCaseAsString("testFail", "pack.ATestCase", ProgressState.COMPLETED, Result.FAILURE, new FailureTrace("junit.framework.AssertionFailedError", null, null), 2),222 TestRunListeners.testCaseAsString("testSucceed", "pack.ATestCase", ProgressState.RUNNING, Result.UNDEFINED, null, 2),223 };224 String[] actual= runTreeTest(aTestCase, 4);225 assertEqualLog(expectedTree, actual);226 }227 public void testTreeUnrootedEnded() throws Exception {228 // regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=153807229 String source=230 "package pack;\n" +231 "\n" +232 "import junit.framework.TestCase;\n" +233 "import junit.framework.TestResult;\n" +234 "import junit.framework.TestSuite;\n" +235 "\n" +236 "public class ATestCase extends TestCase {\n" +237 " public static class RealTest extends TestCase {\n" +238 " public RealTest(String name) {\n" +239 " super(name);\n" +240 " }\n" +241 "\n" +242 " public void myTest1() throws Exception { }\n" +243 "\n" +244 " public void myTest2() throws Exception {\n" +245 " fail();\n" +246 " }\n" +247 " }\n" +248 "\n" +249 " public void testAllTests() { }\n" +250 "\n" +251 " public void run(TestResult result) {\n" +252 " TestSuite suite = new TestSuite(\"MySuite\");\n" +253 " suite.addTest(new RealTest(\"myTest1\"));\n" +254 " suite.addTest(new RealTest(\"myTest2\"));\n" +255 " suite.run(result);\n" +256 " }\n" +257 "}";258 IType aTestCase= createType(source, "pack", "ATestCase.java");259 String[] expectedTree= new String[] {...
Source:4283.java
...48 String[] actual = runSequenceTest(aTestCase);49 assertEqualLog(expectedSequence, actual);50 }51 public void testFail() throws Exception {52 String source = "package pack;\n" + "import junit.framework.TestCase;\n" + "public class ATestCase extends TestCase {\n" + " public void testFail() { fail(); }\n" + "}";53 IType aTestCase = createType(source, "pack", "ATestCase.java");54 String[] expectedSequence = new String[] { "sessionStarted-" + TestRunListeners.sessionAsString("ATestCase", ProgressState.RUNNING, Result.UNDEFINED, 0), "testCaseStarted-" + TestRunListeners.testCaseAsString("testFail", "pack.ATestCase", ProgressState.RUNNING, Result.UNDEFINED, null, 0), "testCaseFinished-" + TestRunListeners.testCaseAsString("testFail", "pack.ATestCase", ProgressState.COMPLETED, Result.FAILURE, new FailureTrace("junit.framework.AssertionFailedError", null, null), 0), "sessionFinished-" + TestRunListeners.sessionAsString("ATestCase", ProgressState.COMPLETED, Result.FAILURE, 0) };55 String[] actual = runSequenceTest(aTestCase);56 assertEqualLog(expectedSequence, actual);57 }58 public void testSimpleTest() throws Exception {59 String source = "package pack;\n" + "import junit.framework.*;\n" + "\n" + "public class ATestCase extends TestCase {\n" + " protected int fValue1;\n" + " protected int fValue2;\n" + "\n" + " public ATestCase(String name) {\n" + " super(name);\n" + " }\n" + " protected void setUp() {\n" + " fValue1= 2;\n" + " fValue2= 3;\n" + " }\n" + " public static Test suite() {\n" + " // ensure ordering:\n" + " TestSuite result= new TestSuite(\"ATestCase\");\n" + " result.addTest(new ATestCase(\"testAdd\"));\n" + " result.addTest(new ATestCase(\"testDivideByZero\"));\n" + " result.addTest(new ATestCase(\"testEquals\"));\n" + " return result;\n" + " }\n" + " public void testAdd() {\n" + " double result= fValue1 + fValue2;\n" + " // forced failure result == 5\n" + " assertTrue(result == 6);\n" + " }\n" + " public void testDivideByZero() {\n" + " int zero= 0;\n" + " int result= 8/zero;\n" + " }\n" + " public void testEquals() {\n" + " assertEquals(12, 12);\n" + " assertEquals(12L, 12L);\n" + " assertEquals(new Long(12), new Long(12));\n" + "\n" + " assertEquals(\"Size\", String.valueOf(12), String.valueOf(13));\n" + " }\n" + " public static void main (String[] args) {\n" + " junit.textui.TestRunner.run(suite());\n" + " }\n" + "}";60 IType aTestCase = createType(source, "pack", "ATestCase.java");61 String[] expectedSequence = new String[] { "sessionStarted-" + TestRunListeners.sessionAsString("ATestCase", ProgressState.RUNNING, Result.UNDEFINED, 0), "testCaseStarted-" + TestRunListeners.testCaseAsString("testAdd", "pack.ATestCase", ProgressState.RUNNING, Result.UNDEFINED, null, 0), "testCaseFinished-" + TestRunListeners.testCaseAsString("testAdd", "pack.ATestCase", ProgressState.COMPLETED, Result.FAILURE, new FailureTrace("junit.framework.AssertionFailedError", null, null), 0), "testCaseStarted-" + TestRunListeners.testCaseAsString("testDivideByZero", "pack.ATestCase", ProgressState.RUNNING, Result.UNDEFINED, null, 0), "testCaseFinished-" + TestRunListeners.testCaseAsString("testDivideByZero", "pack.ATestCase", ProgressState.COMPLETED, Result.ERROR, new FailureTrace("java.lang.ArithmeticException", null, null), 0), "testCaseStarted-" + TestRunListeners.testCaseAsString("testEquals", "pack.ATestCase", ProgressState.RUNNING, Result.UNDEFINED, null, 0), "testCaseFinished-" + TestRunListeners.testCaseAsString("testEquals", "pack.ATestCase", ProgressState.COMPLETED, Result.FAILURE, new FailureTrace("junit.framework.ComparisonFailure", "12", "13"), 0), "sessionFinished-" + TestRunListeners.sessionAsString("ATestCase", ProgressState.COMPLETED, Result.ERROR, 0) };62 String[] actual = runSequenceTest(aTestCase);63 assertEqualLog(expectedSequence, actual);64 }65 public void testTreeOnSessionStarted() throws Exception {66 String source = "package pack;\n" + "import junit.framework.TestCase;\n" + "public class ATestCase extends TestCase {\n" + " public void testSucceed() { }\n" + "}";67 IType aTestCase = createType(source, "pack", "ATestCase.java");68 String[] expectedTree = new String[] { TestRunListeners.sessionAsString("ATestCase", ProgressState.RUNNING, Result.UNDEFINED, 0), TestRunListeners.suiteAsString("pack.ATestCase", ProgressState.NOT_STARTED, Result.UNDEFINED, null, 1), TestRunListeners.testCaseAsString("testSucceed", "pack.ATestCase", ProgressState.NOT_STARTED, Result.UNDEFINED, null, 2) };69 String[] actual = runTreeTest(aTestCase, 1);70 assertEqualLog(expectedTree, actual);71 }72 public void testTreeOnSessionEnded() throws Exception {73 String source = "package pack;\n" + "import junit.framework.TestCase;\n" + "public class ATestCase extends TestCase {\n" + " public void testFail() { fail(); }\n" + "}";74 IType aTestCase = createType(source, "pack", "ATestCase.java");75 String[] expectedTree = new String[] { TestRunListeners.sessionAsString("ATestCase", ProgressState.COMPLETED, Result.FAILURE, 0), TestRunListeners.suiteAsString("pack.ATestCase", ProgressState.COMPLETED, Result.FAILURE, null, 1), TestRunListeners.testCaseAsString("testFail", "pack.ATestCase", ProgressState.COMPLETED, Result.FAILURE, new FailureTrace("junit.framework.AssertionFailedError", null, null), 2) };76 String[] actual = runTreeTest(aTestCase, 4);77 assertEqualLog(expectedTree, actual);78 }79 public void testTreeOnSecondTestStarted() throws Exception {80 String source = "package pack;\n" + "import junit.framework.*;\n" + "public class ATestCase extends TestCase {\n" + " public static Test suite() {\n" + " // ensure ordering:\n" + " TestSuite result= new TestSuite(\"pack.ATestCase\");\n" + " result.addTest(new ATestCase(\"testSucceed\"));\n" + " result.addTest(new ATestCase(\"testFail\"));\n" + " return result;\n" + " }\n" + " public ATestCase(String name) {\n" + " super(name);\n" + " }\n" + " public void testSucceed() { }\n" + " public void testFail() { fail(); }\n" + "}";81 IType aTestCase = createType(source, "pack", "ATestCase.java");82 String[] expectedTree = new String[] { TestRunListeners.sessionAsString("ATestCase", ProgressState.RUNNING, Result.UNDEFINED, 0), TestRunListeners.suiteAsString("pack.ATestCase", ProgressState.RUNNING, Result.UNDEFINED, null, 1), TestRunListeners.testCaseAsString("testSucceed", "pack.ATestCase", ProgressState.COMPLETED, Result.OK, null, 2), TestRunListeners.testCaseAsString("testFail", "pack.ATestCase", ProgressState.RUNNING, Result.UNDEFINED, null, 2) };83 String[] actual = runTreeTest(aTestCase, 4);84 assertEqualLog(expectedTree, actual);85 }86 public void testTreeOnSecondTestStarted2() throws Exception {87 String source = "package pack;\n" + "import junit.framework.*;\n" + "public class ATestCase extends TestCase {\n" + " public static Test suite() {\n" + " // ensure ordering:\n" + " TestSuite result= new TestSuite(\"pack.ATestCase\");\n" + " result.addTest(new ATestCase(\"testFail\"));\n" + " result.addTest(new ATestCase(\"testSucceed\"));\n" + " return result;\n" + " }\n" + " public ATestCase(String name) {\n" + " super(name);\n" + " }\n" + " public void testFail() { fail(); }\n" + " public void testSucceed() { }\n" + "}";88 IType aTestCase = createType(source, "pack", "ATestCase.java");89 String[] expectedTree = new String[] { TestRunListeners.sessionAsString("ATestCase", ProgressState.RUNNING, Result.FAILURE, 0), TestRunListeners.suiteAsString("pack.ATestCase", ProgressState.RUNNING, Result.FAILURE, null, 1), TestRunListeners.testCaseAsString("testFail", "pack.ATestCase", ProgressState.COMPLETED, Result.FAILURE, new FailureTrace("junit.framework.AssertionFailedError", null, null), 2), TestRunListeners.testCaseAsString("testSucceed", "pack.ATestCase", ProgressState.RUNNING, Result.UNDEFINED, null, 2) };90 String[] actual = runTreeTest(aTestCase, 4);91 assertEqualLog(expectedTree, actual);92 }93 public void testTreeUnrootedEnded() throws Exception {94 // regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=15380795 String source = "package pack;\n" + "\n" + "import junit.framework.TestCase;\n" + "import junit.framework.TestResult;\n" + "import junit.framework.TestSuite;\n" + "\n" + "public class ATestCase extends TestCase {\n" + " public static class RealTest extends TestCase {\n" + " public RealTest(String name) {\n" + " super(name);\n" + " }\n" + "\n" + " public void myTest1() throws Exception { }\n" + "\n" + " public void myTest2() throws Exception {\n" + " fail();\n" + " }\n" + " }\n" + "\n" + " public void testAllTests() { }\n" + "\n" + " public void run(TestResult result) {\n" + " TestSuite suite = new TestSuite(\"MySuite\");\n" + " suite.addTest(new RealTest(\"myTest1\"));\n" + " suite.addTest(new RealTest(\"myTest2\"));\n" + " suite.run(result);\n" + " }\n" + "}";96 IType aTestCase = createType(source, "pack", "ATestCase.java");97 String[] expectedTree = new String[] { TestRunListeners.sessionAsString("ATestCase", ProgressState.COMPLETED, Result.FAILURE, 0), TestRunListeners.suiteAsString("pack.ATestCase", ProgressState.NOT_STARTED, Result.UNDEFINED, null, 1), TestRunListeners.testCaseAsString("testAllTests", "pack.ATestCase", ProgressState.NOT_STARTED, Result.UNDEFINED, null, 2), TestRunListeners.suiteAsString(JUnitMessages.TestRunSession_unrootedTests, ProgressState.COMPLETED, Result.FAILURE, null, 1), TestRunListeners.testCaseAsString("myTest1", "pack.ATestCase.RealTest", ProgressState.COMPLETED, Result.OK, null, 2), TestRunListeners.testCaseAsString("myTest2", "pack.ATestCase.RealTest", ProgressState.COMPLETED, Result.FAILURE, new FailureTrace("junit.framework.AssertionFailedError", null, null), 2) };98 String[] actual = runTreeTest(aTestCase, 6);99 assertEqualLog(expectedTree, actual);100 }101 public void testTreeJUnit4TestAdapter() throws Exception {102 // regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=397747103 IClasspathEntry cpe = JavaCore.newContainerEntry(JUnitCore.JUNIT4_CONTAINER_PATH);104 JavaProjectHelper.clear(fProject, new IClasspathEntry[] { cpe });105 JavaProjectHelper.addRTJar15(fProject);106 String source = "package test;\n" + "\n" + "import junit.framework.JUnit4TestAdapter;\n" + "import junit.framework.TestCase;\n" + "import junit.framework.TestSuite;\n" + "\n" + "import org.junit.Test;\n" + "import org.junit.runner.RunWith;\n" + "import org.junit.runners.Suite;\n" + "import org.junit.runners.Suite.SuiteClasses;\n" + "\n" + "public class MyTestSuite {\n" + " public static junit.framework.Test suite() {\n" + " TestSuite suite = new TestSuite();\n" + " suite.addTest(new JUnit4TestAdapter(JUnit4TestSuite.class));\n" + " suite.addTestSuite(JUnit3TestCase.class);\n" + " return suite;\n" + " }\n" + " \n" + " @RunWith(Suite.class)\n" + " @SuiteClasses({JUnit4TestCase.class})\n" + " public static class JUnit4TestSuite {}\n" + " \n" + " public static class JUnit4TestCase {\n" + " @Test public void testA() {}\n" + " @Test public void testB() {}\n" + " }\n" + " \n" + " public static class JUnit3TestCase extends TestCase {\n" + " public void testC() {}\n" + " public void testD() {}\n" + " public void testE() {}\n" + " }\n" + "}\n";107 IType aTestCase = createType(source, "test", "MyTestSuite.java");108 String[] expectedTree = new String[] { TestRunListeners.sessionAsString("MyTestSuite", ProgressState.COMPLETED, Result.OK, 0), TestRunListeners.suiteAsString("junit.framework.TestSuite", ProgressState.COMPLETED, Result.OK, null, 1), TestRunListeners.suiteAsString("test.MyTestSuite.JUnit4TestSuite", ProgressState.COMPLETED, Result.OK, null, 2), TestRunListeners.suiteAsString("test.MyTestSuite.JUnit4TestCase", ProgressState.COMPLETED, Result.OK, null, 3), TestRunListeners.testCaseAsString("testA", "test.MyTestSuite.JUnit4TestCase", ProgressState.COMPLETED, Result.OK, null, 4), TestRunListeners.testCaseAsString("testB", "test.MyTestSuite.JUnit4TestCase", ProgressState.COMPLETED, Result.OK, null, 4), TestRunListeners.suiteAsString("test.MyTestSuite.JUnit3TestCase", ProgressState.COMPLETED, Result.OK, null, 2), TestRunListeners.testCaseAsString("testC", "test.MyTestSuite.JUnit3TestCase", ProgressState.COMPLETED, Result.OK, null, 3), TestRunListeners.testCaseAsString("testD", "test.MyTestSuite.JUnit3TestCase", ProgressState.COMPLETED, Result.OK, null, 3), TestRunListeners.testCaseAsString("testE", "test.MyTestSuite.JUnit3TestCase", ProgressState.COMPLETED, Result.OK, null, 3) };109 String[] actual = runTreeTest(aTestCase, 12);...
Source:ConfigurationXmlParserTest.java
...110 final String config =111 "<object name=\"foo\" />";112 try {113 xmlParser.parse("name", getStringAsStream(config));114 fail("ConfigurationException not thrown");115 } catch (ConfigurationException e) {116 // expected117 }118 }119120 /**121 * Test parsing a option tag missing a attribute.122 */123 public void testParse_optionMissingAttr() {124 final String config =125 "<option name=\"foo\" />";126 try {127 xmlParser.parse("name", getStringAsStream(config));128 fail("ConfigurationException not thrown");129 } catch (ConfigurationException e) {130 // expected131 }132 }133134 /**135 * Test parsing a object tag.136 */137 public void testParse_object() throws ConfigurationException {138 final String config =139 "<object type=\"foo\" class=\"junit.framework.TestCase\" />";140 ConfigurationDef configDef = xmlParser.parse("name", getStringAsStream(config));141 assertEquals("junit.framework.TestCase", configDef.getObjectClassMap().get("foo").get(0));142 }143144 /**145 * Test parsing a include tag.146 */147 public void testParse_include() throws ConfigurationException {148 final String includedConfig = "<object type=\"foo\" class=\"junit.framework.TestCase\" />";149 String includedName = "includeme";150 ConfigurationDef includedConfigDef = xmlParser.parse(includedName,151 getStringAsStream(includedConfig));152 EasyMock.expect(mMockLoader.getConfigurationDef(includedName)).andReturn(includedConfigDef);153 EasyMock.replay(mMockLoader);154 final String config = "<include name=\"includeme\" />";155 ConfigurationDef configDef = xmlParser.parse("name", getStringAsStream(config));156 assertEquals("junit.framework.TestCase", configDef.getObjectClassMap().get("foo").get(0));157 }158159 /**160 * Test parsing a include tag where named config does not exist161 */162 public void testParse_includeMissing() throws ConfigurationException {163 String includedName = "non-existent";164 ConfigurationException exception = new ConfigurationException("I don't exist");165 EasyMock.expect(mMockLoader.getConfigurationDef(includedName)).andThrow(exception);166 EasyMock.replay(mMockLoader);167 final String config = String.format("<include name=\"%s\" />", includedName);168 try {169 xmlParser.parse("name", getStringAsStream(config));170 fail("ConfigurationException not thrown");171 } catch (ConfigurationException e) {172 // expected173 }174 }175176 /**177 * Test parsing invalid xml.178 */179 public void testParse_xml() throws ConfigurationException {180 final String config = "blah";181 try {182 xmlParser.parse("name", getStringAsStream(config));183 fail("ConfigurationException not thrown");184 } catch (ConfigurationException e) {185 // expected186 }187 }188189 private InputStream getStringAsStream(String input) {190 return new ByteArrayInputStream(input.getBytes());191 }192}
...
Source:TestStacktrace.java
...20 }2122 public void testExcludingJUnitStackTrace() throws IOException {23 String[] args = new String[]{24 "./tests/edu/washington/cs/dt/samples/havefails.txt",25 className + ".test1",26 className + ".test2",27 className + ".test4",28 className + ".test5"29 };30 TestRunnerWrapper.main(args);31 }32 33 public void testAssertionWrong() {34 String regex = Main.excludeRegex;35 36 String str1 = "junit.framework.TestRunner";37 38 Pattern p = Pattern.compile(regex);39 assertTrue(TestExecUtils.shouldExclude(str1, p, TestExecUtils.JUNIT_ASSERT));40 41 String str2 = "junit.framework.Assert";;42 assertTrue(!TestExecUtils.shouldExclude(str2, p, TestExecUtils.JUNIT_ASSERT));43 44 String str3 = "junit.framework.TestSuite.runTest(TestSuite.java:208)";45 assertTrue(TestExecUtils.shouldExclude(str3, p, TestExecUtils.JUNIT_ASSERT));46 }47 48 public void testComparingJFreeChartStackTraces() {49 String regex = Main.excludeRegex;50 Pattern p = Pattern.compile(regex);51 String[] fixedOrders = new String[] {52 "junit.framework.AssertionFailedError: expected:<1.2322332E12> but was:<1.232233199999E12>",53 "junit.framework.Assert.fail(Assert.java:47)",54 "junit.framework.Assert.failNotEquals(Assert.java:282)",55 "junit.framework.Assert.assertEquals(Assert.java:101)",56 "junit.framework.Assert.assertEquals(Assert.java:108)",57 "org.jfree.chart.axis.junit.PeriodAxisTests.test2490803(PeriodAxisTests.java:326)",58 "sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)",59 "sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)",60 "sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)",61 "java.lang.reflect.Method.invoke(Method.java:601)",62 "junit.framework.TestCase.runTest(TestCase.java:154)",63 "junit.framework.TestCase.runBare(TestCase.java:127)",64 "junit.framework.TestResult$1.protect(TestResult.java:106)",65 "junit.framework.TestResult.runProtected(TestResult.java:124)",66 "junit.framework.TestResult.run(TestResult.java:109)",67 "junit.framework.TestCase.run(TestCase.java:118)",68 "junit.framework.TestSuite.runTest(TestSuite.java:208)",69 "junit.framework.TestSuite.run(TestSuite.java:203)",70 "junit.framework.TestSuite.runTest(TestSuite.java:208)",71 "junit.framework.TestSuite.run(TestSuite.java:203)",72 "org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)",73 "org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)",74 "org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)",75 "org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)",76 "org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)",77 "org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)"7879 };80 String[] isolations = new String[] {81 "junit.framework.AssertionFailedError: expected:<1.2322332E12> but was:<1.232233199999E12>",82 "junit.framework.Assert.fail(Assert.java:47)",83 "junit.framework.Assert.failNotEquals(Assert.java:282)",84 "junit.framework.Assert.assertEquals(Assert.java:101)",85 "junit.framework.Assert.assertEquals(Assert.java:108)",86 "org.jfree.chart.axis.junit.PeriodAxisTests.test2490803(PeriodAxisTests.java:326)",87 "sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)",88 "sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)",89 "sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)",90 "java.lang.reflect.Method.invoke(Method.java:601)",91 "junit.framework.TestCase.runTest(TestCase.java:154)",92 "junit.framework.TestCase.runBare(TestCase.java:127)",93 "junit.framework.TestResult$1.protect(TestResult.java:106)",94 "junit.framework.TestResult.runProtected(TestResult.java:124)",95 "junit.framework.TestResult.run(TestResult.java:109)",96 "junit.framework.TestCase.run(TestCase.java:118)",97 "org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)",
...
Source:TestResultWithExpectedFailures.java
...23/**24 * A {@link TestResult} that can interpret {@link ExpectedFailure} on test methods.25 */26class TestResultWithExpectedFailures extends ForwardingTestResult {27 private boolean failed;28 public TestResultWithExpectedFailures(TestResult delegate) {29 super(delegate);30 }31 @Override32 public void startTest(Test test) {33 failed = false;34 super.startTest(test);35 }36 @Override37 public void addFailure(Test test, AssertionFailedError t) {38 failed = true;39 if (isTestExpectedToFail(test)) {40 processException(test, t);41 } else {42 super.addFailure(test, t);43 }44 }45 @Override46 public void addError(Test test, Throwable t) {47 failed = true;48 if (isTestExpectedToFail(test)) {49 processException(test, t);50 } else {51 super.addError(test, t);52 }53 }54 @Override55 public void endTest(Test test) {56 if (!failed && isTestExpectedToFail(test)) {57 // Test should have failed but didn't. Report the failure by calling the super directly to58 // prevent any interference from overridden #addFailure.59 super.addFailure(test, new AssertionFailedError("Expected failure but didn't fail"));60 }61 super.endTest(test);62 }63 private boolean isTestExpectedToFail(Test test) {64 return getExpectedFailureAnnotation(test) != null;65 }66 private void processException(Test test, Throwable t) {67 ExpectedFailure annotation = getExpectedFailureAnnotation(test);68 try {69 annotation.withAsserter().newInstance().assertException(annotation, t);70 } catch (AssertionFailedError e) {71 String msg = "Assertion failed for thrown exception: " + e.getMessage()72 + "\n(Actual thrown exception is reported below via 'caused by')";73 AssertionFailedError errorToReport = new AssertionFailedError(msg);74 errorToReport.initCause(t);75 errorToReport.setStackTrace(e.getStackTrace());76 super.addFailure(test, errorToReport);77 } catch (Exception e) {78 super.addError(test, e);79 }80 }81 private ExpectedFailure getExpectedFailureAnnotation(Test test) {82 if (test instanceof TestCase) {83 TestCase testCase = (TestCase) test;84 try {85 Method testMethod = testCase.getClass().getMethod(testCase.getName());...
Source:ExtensionTest.java
...23 fTornDown= true;24 }25 }26 public void testRunningErrorInTestSetup() {27 TestCase test= new TestCase("failure") {28 @Override29 public void runTest() {30 fail();31 }32 };3334 TestSetup wrapper= new TestSetup(test);3536 TestResult result= new TestResult();37 wrapper.run(result);38 assertTrue(!result.wasSuccessful());39 }40 public void testRunningErrorsInTestSetup() {41 TestCase failure= new TestCase("failure") {42 @Override43 public void runTest() {44 fail();45 }46 };4748 TestCase error= new TestCase("error") {49 @Override50 public void runTest() {51 throw new Error();52 }53 };5455 TestSuite suite= new TestSuite();56 suite.addTest(failure);57 suite.addTest(error);58 59 TestSetup wrapper= new TestSetup(suite);6061 TestResult result= new TestResult();62 wrapper.run(result);6364 assertEquals(1, result.failureCount());65 assertEquals(1, result.errorCount());66 }67 public void testSetupErrorDontTearDown() {68 WasRun test= new WasRun();6970 TornDown wrapper= new TornDown(test) {71 @Override72 public void setUp() {73 fail();74 }75 };7677 TestResult result= new TestResult();78 wrapper.run(result);7980 assertTrue(!wrapper.fTornDown);81 }82 public void testSetupErrorInTestSetup() {83 WasRun test= new WasRun();8485 TestSetup wrapper= new TestSetup(test) {86 @Override87 public void setUp() {88 fail();89 }90 };9192 TestResult result= new TestResult();93 wrapper.run(result);9495 assertTrue(!test.fWasRun);96 assertTrue(!result.wasSuccessful());97 }
...
Source:StackFilterTest.java
...14 protected void setUp() {15 StringWriter swin= new StringWriter();16 PrintWriter pwin= new PrintWriter(swin);17 pwin.println("junit.framework.AssertionFailedError");18 pwin.println(" at junit.framework.Assert.fail(Assert.java:144)");19 pwin.println(" at junit.framework.Assert.assert(Assert.java:19)");20 pwin.println(" at junit.framework.Assert.assert(Assert.java:26)");21 pwin.println(" at MyTest.f(MyTest.java:13)");22 pwin.println(" at MyTest.testStackTrace(MyTest.java:8)");23 pwin.println(" at java.lang.reflect.Method.invoke(Native Method)");24 pwin.println(" at junit.framework.TestCase.runTest(TestCase.java:156)");25 pwin.println(" at junit.framework.TestCase.runBare(TestCase.java:130)");26 pwin.println(" at junit.framework.TestResult$1.protect(TestResult.java:100)");27 pwin.println(" at junit.framework.TestResult.runProtected(TestResult.java:118)");28 pwin.println(" at junit.framework.TestResult.run(TestResult.java:103)");29 pwin.println(" at junit.framework.TestCase.run(TestCase.java:121)");30 pwin.println(" at junit.framework.TestSuite.runTest(TestSuite.java:157)");31 pwin.println(" at junit.framework.TestSuite.run(TestSuite.java, Compiled Code)");32 pwin.println(" at junit.swingui.TestRunner$17.run(TestRunner.java:669)");
...
fail
Using AI Code Generation
1import junit.framework.TestCase;2public class Test extends TestCase {3 public void testFail() {4 fail("This test always fails");5 }6}7import junit.framework.TestCase;8public class Test extends TestCase {9 public void testAssertTrue() {10 assertTrue("This test always passes", true);11 }12}13import junit.framework.TestCase;14public class Test extends TestCase {15 public void testAssertFalse() {16 assertFalse("This test always fails", false);17 }18}19import junit.framework.TestCase;20public class Test extends TestCase {21 public void testAssertEquals() {22 assertEquals("This test always passes", "abc", "abc");23 }24}25import junit.framework.TestCase;26public class Test extends TestCase {27 public void testAssertNotEquals() {28 assertNotEquals("This test always passes", "abc", "xyz");29 }30}31import junit.framework.TestCase;32public class Test extends TestCase {33 public void testAssertNull() {34 assertNull("This test always passes", null);35 }36}37import junit.framework.TestCase;38public class Test extends TestCase {39 public void testAssertNotNull() {40 assertNotNull("This test always passes", new Object());41 }42}43import junit.framework.TestCase;44public class Test extends TestCase {45 public void testAssertSame() {46 assertSame("This test always passes", "abc", "abc");47 }48}49import junit.framework.TestCase;50public class Test extends TestCase {51 public void testAssertNotSame() {52 assertNotSame("This test always passes", "abc", "xyz");53 }54}55import junit.framework.TestCase;56public class Test extends TestCase {57 public void testAssertArrayEquals() {58 int[] a = {1, 2, 3};59 int[] b = {1, 2, 3};60 assertArrayEquals("This test always passes", a, b);61 }62}
fail
Using AI Code Generation
1import junit.framework.TestCase;2public class Test extends TestCase {3 public void testFail() {4 fail("This test always fails");5 }6}7import junit.framework.TestCase;8public class Test extends TestCase {9 public void testAssertTrue() {10 assertTrue(true);11 }12}13import junit.framework.TestCase;14public class Test extends TestCase {15 public void testAssertFalse() {16 assertFalse(false);17 }18}19import junit.framework.TestCase;20public class Test extends TestCase {21 public void testAssertEquals() {22 assertEquals(1, 1);23 }24}25import junit.framework.TestCase;26public class Test extends TestCase {27 public void testAssertSame() {28 assertSame(1, 1);29 }30}31import junit.framework.TestCase;32public class Test extends TestCase {33 public void testAssertNull() {34 assertNull(null);35 }36}37import junit.framework.TestCase;38public class Test extends TestCase {39 public void testAssertNotNull() {40 assertNotNull(1);41 }42}43import junit.framework.TestCase;44public class Test extends TestCase {45 public void testAssertNotSame() {46 assertNotSame(1, 2);47 }48}49import junit.framework.TestCase;50public class Test extends TestCase {51 public void testAssertNotEquals() {52 assertNotEquals(1, 2);53 }54}55import junit.framework.TestCase;56public class Test extends TestCase {57 public void testAssertArrayEquals() {58 int[] a = {1, 2, 3};59 int[] b = {1, 2, 3};60 assertArrayEquals(a, b);61 }62}63import junit.framework.TestCase;64public class Test extends TestCase {65 public void testAssertNotSame() {66 assertNotSame(1, 2);67 }68}69import junit.framework.TestCase;70public class Test extends TestCase {
fail
Using AI Code Generation
1import junit.framework.TestCase;2public class Test extends TestCase {3 public void test() {4 fail("error message");5 }6}7import static org.hamcrest.MatcherAssert.assertThat;8import static org.hamcrest.Matchers.is;9import static org.hamcrest.Matchers.equalTo;10public class Test {11 public void test() {12 assertThat("error message", 1, is(equalTo(2)));13 }14}15The following code shows how to use the fail method of the junit.framework.TestCase class to fail a test case. import junit.framework.TestCase; public class Test extends TestCase { public void test() { fail("error message"); } } The following code shows how to use the assertThat method of the org.hamcrest.MatcherAssert class to fail a test case. import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.equalTo; public class Test { @Test public void test() { assertThat("error message", 1, is(equalTo(2))); } }
fail
Using AI Code Generation
1import junit.framework.TestCase;2public class Test extends TestCase {3 public void test() {4 fail("This test always fails");5 }6}7import junit.framework.TestCase;8public class Test extends TestCase {9 public void test() {10 assertSame("failure - strings are not same", "text", "text");11 }12}13import junit.framework.TestCase;14public class Test extends TestCase {15 public void test() {16 assertNotSame("failure - strings are same", "text", "text");17 }18}19import junit.framework.TestCase;20public class Test extends TestCase {21 public void test() {22 assertEquals("failure - strings are not equal", "text", "text");23 }24}25import junit.framework.TestCase;26public class Test extends TestCase {27 public void test() {28 assertTrue("failure - should be true", true);29 }30}31import junit.framework.TestCase;32public class Test extends TestCase {33 public void test() {34 assertFalse("failure - should be false", false);35 }36}37import junit.framework.TestCase;38public class Test extends TestCase {39 public void test() {40 assertNull("should be null", null);41 }42}43import junit.framework.TestCase;44public class Test extends TestCase {45 public void test() {46 assertNotNull("should not be null", new Object());47 }48}49import junit.framework.TestCase;50public class Test extends TestCase {51 public void test() {52 assertSame("should be same", new Object(), new Object());53 }54}55import junit.framework.TestCase;56public class Test extends TestCase {57 public void test() {58 assertNotSame("should not be same", new Object(), new Object());59 }60}61import junit.framework.TestCase;62public class Test extends TestCase {63 public void test() {64 assertArrayEquals("failure - byte arrays not same", new byte[] { 1, 2,
fail
Using AI Code Generation
1public void testArraySort_RandomArray() {2int[] numbers = {12,3,4,1};3int[] expected = {1,3,4,12};4Arrays.sort(numbers);5assertArrayEquals(expected, numbers);6}7public void testArraySort_RandomArray() {8int[] numbers = {12,3,4,1};9int[] expected = {1,3,4,12};10Arrays.sort(numbers);11assertTrue(Arrays.equals(expected, numbers));12}13public void testArraySort_RandomArray() {14int[] numbers = {12,3,4,1};15int[] expected = {1,3,4,12};16Arrays.sort(numbers);17assertThat(numbers, is(expected));18}19public void testArraySort_RandomArray() {20int[] numbers = {12,3,4,1};21int[] expected = {1,3,4,12};22Arrays.sort(numbers);23assertEquals(expected, numbers);24}25public void testArraySort_RandomArray() {26int[] numbers = {12,3,4,1};27int[] expected = {1,3,4,12};28Arrays.sort(numbers);29assertThat(numbers, is(expected));30}31public void testArraySort_RandomArray() {32int[] numbers = {12,3,4,1};33int[] expected = {1,3,4,12};34Arrays.sort(numbers);35assertThat(numbers, is(expected));36}37public void testArraySort_RandomArray() {38int[] numbers = {12,3,4,1};39int[] expected = {1,3,4,12};40Arrays.sort(numbers);
fail
Using AI Code Generation
1import junit.framework.TestCase;2public class Test extends TestCase {3public void test() {4fail("I am failing");5}6}7import junit.framework.TestCase;8public class Test extends TestCase {9public void test() {10assert(false);11}12}13import junit.framework.TestCase;14public class Test extends TestCase {15public void test() {16assertSame("a", "a");17}18}19import junit.framework.TestCase;20public class Test extends TestCase {21public void test() {22assertEquals("a", "a");23}24}25import junit.framework.TestCase;26public class Test extends TestCase {27public void test() {28assertTrue(true);29}30}31import junit.framework.TestCase;32public class Test extends TestCase {33public void test() {34assertFalse(false);35}36}37import junit.framework.TestCase;38public class Test extends TestCase {39public void test() {40assertNull(null);41}42}43import junit.framework.TestCase;44public class Test extends TestCase {45public void test() {46assertNotNull("a");47}48}49import junit.framework.TestCase;50public class Test extends TestCase {51public void test() {52assertNotSame("a", "b");53}54}55import junit.framework.TestCase;56public class Test extends TestCase {57public void test() {58assertNotEquals("a", "b");59}60}61import junit.framework.TestCase;62public class Test extends TestCase {63public void test() {64assertNotEquals("a", "b");65}66}67import junit.framework.TestCase;68public class Test extends TestCase {69public void test() {70assertArrayEquals(new int[]{1, 2, 3}, new int[]{1, 2, 3});71}72}73import junit.framework.TestCase;74import java.util.Arrays;75public class Test extends TestCase {76public void test() {77assertSameElements(Arrays.asList("a", "b", "c"), Arrays.asList("
fail
Using AI Code Generation
1import junit.framework.TestCase;2public class Test extends TestCase {3 public void test() {4 fail("This is a test");5 }6}7import junit.framework.TestCase;8public class Test extends TestCase {9 public void test() {10 assert(true);11 }12}13import junit.framework.TestCase;14public class Test extends TestCase {15 public void test() {16 assertTrue(true);17 }18}19import junit.framework.TestCase;20public class Test extends TestCase {21 public void test() {22 assertFalse(false);23 }24}25import junit.framework.TestCase;26public class Test extends TestCase {27 public void test() {28 assertEquals(1, 1);29 }30}31import junit.framework.TestCase;32public class Test extends TestCase {33 public void test() {34 assertNotEquals(1, 2);35 }36}37import junit.framework.TestCase;38public class Test extends TestCase {39 public void test() {40 assertNull(null);41 }42}43import junit.framework.TestCase;44public class Test extends TestCase {45 public void test() {46 assertNotNull("Not null");47 }48}49import junit.framework.TestCase;50public class Test extends TestCase {51 public void test() {52 String str1 = new String("Hello");53 String str2 = new String("Hello");54 assertSame(str1, str2);55 }56}57import junit.framework.TestCase;58public class Test extends TestCase {59 public void test() {60 String str1 = new String("Hello");61 String str2 = new String("Hello");62 assertNotSame(str1, str2);63 }64}65import junit.framework.TestCase;66public class Test extends TestCase {67 public void test() {68 int[] arr1 = {1, 2, 3};69 int[] arr2 = {1, 2, 3};70 assertArrayEquals(arr1, arr2);71 }72}
fail
Using AI Code Generation
1import junit.framework.TestCase;2import org.junit.Test;3public class TestFail extends TestCase {4 public void testFail() {5 fail("failure message");6 }7}
LambdaTest also has a detailed JUnit tutorial explaining its features, importance, advanced use cases, best practices, and more to help you get started with running your automation testing scripts.
Here are the detailed JUnit testing chapters to help you get started:
You can also check out our JUnit certification if you wish to take your career in Selenium automation testing with JUnit to the next level.
Get 100 minutes of automation test minutes FREE!!