File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\test\src\test\java\hudson\tasks\junit\HistoryTest.java.html

1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2009, Yahoo!, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24 package hudson.tasks.junit;
25
26 import hudson.model.FreeStyleBuild;
27 import hudson.model.FreeStyleProject;
28 import hudson.model.Project;
29 import hudson.model.Result;
30 import org.jvnet.hudson.test.HudsonTestCase;
31 import org.jvnet.hudson.test.recipes.LocalData;
32
33 import java.util.List;
34
35 public class HistoryTest extends HudsonTestCase {
36 private FreeStyleProject project;
37
38 private static final String PROJECT_NAME = "wonky";
39
40
41 @Override
42 protected void setUp() throws Exception {
43 super.setUp();
44
45 List<Project> projects = this.jenkins.getProjects();
46 Project theProject = null;
47 for (Project p : projects) {
48 if (p.getName().equals(PROJECT_NAME)) theProject = p;
49 }
50 assertNotNull("We should have a project named " + PROJECT_NAME, theProject);
51
52 assertTrue( theProject instanceof FreeStyleProject);
53 project = (FreeStyleProject) theProject;
54 }
55
56
57 @LocalData
58 public void testFailedSince() throws Exception {
59 assertNotNull("project should exist", project);
60
61 // Check the status of a few builds
62 FreeStyleBuild build4 = project.getBuildByNumber(4);
63 assertNotNull("build4", build4);
64 assertBuildStatus(Result.FAILURE, build4);
65
66 FreeStyleBuild build7 = project.getBuildByNumber(7);
67 assertNotNull("build7", build7);
68 assertBuildStatus(Result.SUCCESS, build7);
69
70 TestResult tr = build4.getAction(TestResultAction.class).getResult();
71 assertEquals(2,tr.getFailedTests().size());
72
73 // In build 4, we expect these tests to have failed since these builds
74 // org.jvnet.hudson.examples.small.deep.DeepTest.testScubaGear failed since 3
75 // org.jvnet.hudson.examples.small.MiscTest.testEleanor failed since 3
76
77 PackageResult deepPackage = tr.byPackage("org.jvnet.hudson.examples.small.deep");
78 assertNotNull("deepPackage", deepPackage);
79 assertTrue("package is failed", !deepPackage.isPassed());
80 ClassResult deepClass = deepPackage.getClassResult("DeepTest");
81 assertNotNull(deepClass);
82 assertTrue("class is failed", !deepClass.isPassed());
83 CaseResult scubaCase = deepClass.getCaseResult("testScubaGear");
84 assertNotNull(scubaCase);
85 assertTrue("scubaCase case is failed", !scubaCase.isPassed());
86 int scubaFailedSince = scubaCase.getFailedSince();
87 assertEquals("scubaCase should have failed since build 3", 3, scubaFailedSince);
88
89
90 // In build 5 the scuba test begins to pass
91 TestResult tr5 = project.getBuildByNumber(5).getAction(TestResultAction.class).getResult();
92 assertEquals(1,tr5.getFailedTests().size());
93 deepPackage = tr5.byPackage("org.jvnet.hudson.examples.small.deep");
94 assertNotNull("deepPackage", deepPackage);
95 assertTrue("package is passed", deepPackage.isPassed());
96 deepClass = deepPackage.getClassResult("DeepTest");
97 assertNotNull(deepClass);
98 assertTrue("class is passed", deepClass.isPassed());
99 scubaCase = deepClass.getCaseResult("testScubaGear");
100 assertNotNull(scubaCase);
101 assertTrue("scubaCase case is passed", scubaCase.isPassed());
102
103 // In build5, testEleanor has been failing since build 3
104 PackageResult smallPackage = tr5.byPackage("org.jvnet.hudson.examples.small");
105 ClassResult miscClass = smallPackage.getClassResult("MiscTest");
106 CaseResult eleanorCase = miscClass.getCaseResult("testEleanor");
107 assertTrue("eleanor failed", !eleanorCase.isPassed());
108 assertEquals("eleanor has failed since build 3", 3, eleanorCase.getFailedSince());
109 }
110 }
111