tutorials.de Buch-Aktion 05/2012
Seite 2 von 2 ErsteErste 12
ERLEDIGT
NEIN
ANTWORTEN
17
ZUGRIFFE
611
EMPFEHLEN
  • An Twitter übertragen
  • An Facebook übertragen
AUF DIESES THEMA
ANTWORTEN
  1. #16
    mockauer mockauer ist offline Mitglied
    Registriert seit
    Mar 2011
    Beiträge
    15
    Ich habe von meinen Chef diese Datei bekommen mit der aufgabe alle gets in eine HTML datei zu bekommen, das geht ja schon super, und eben dass es oben sofort anzeigt welches Testcases ok sind und welche ncht ok, dort hängt es, soll anzeigen: nicht erfolgreich: 2 und erfolgreich:3 (bsp.werte)
     

  2. #17
    Avatar von Fabio Hellmann
    Fabio Hellmann Fabio Hellmann ist offline Mitglied Brokat
    Registriert seit
    Aug 2011
    Ort
    München
    Beiträge
    494
    Hier mal eine Programmstruktur, wie ich es auf die Schnelle machen würde.
    Den Code musst du zum Teil noch an deine Bedürfnisse anpassen. Sprich die Klasse TestCase und die Filenamen, etc. .

    Code java:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    
    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.util.ArrayList;
    import java.util.List;
     
    public class TestCaseAnalyser
    {
        /**
         * @param args
         */
        public static void main(String[] args) {
            TestCaseAnalyser analyser = new TestCaseAnalyser();
            List<TestCase> testCases = analyser.loadTestCases(new File("DeineDatei.txt"));
            analyser.wrapToHtml(new File("DeineHtmlDatei.html"), testCases);
        }
     
        /**
         * @param file
         * @return
         */
        public List<TestCase> loadTestCases(File file) {
            List<TestCase> testCases = new ArrayList<TestCase>();
     
            BufferedReader reader = null;
            try {
                reader = new BufferedReader(new FileReader(file));
     
                String line;
                while((line = reader.readLine()) != null) {
                    int countSuccess = countWord(line, "is successfull", false);
                    int countNotSuccess = countWord(line, "not successfull", false);
     
                    testCases.add(new TestCase(line, countSuccess, countNotSuccess));
                }
            } catch(FileNotFoundException e) {
                e.printStackTrace();
            } catch(IOException e) {
                e.printStackTrace();
            } finally {
                if(reader != null) {
                    try {
                        reader.close();
                    } catch(IOException e) {
                        e.printStackTrace();
                    }
                }
            }
            return testCases;
        }
     
        /**
         * @param string
         * @param searched
         * @return
         */
        public int countWord(String string, String searched, boolean caseSensitive) {
            if(!caseSensitive) {
                string = string.toLowerCase();
                searched = searched.toLowerCase();
            }
     
            int startIndex = 0;
            int wordIndex = 0;
     
            int count = 0;
            while((wordIndex = string.indexOf(searched, startIndex)) != -1) {
                startIndex = wordIndex + searched.length();
                count++;
            }
            return count;
        }
     
        /**
         * @param outputFile
         * @param testCases
         */
        public void wrapToHtml(File outputFile, List<TestCase> testCases) {
            BufferedWriter writer = null;
            try {
                writer = new BufferedWriter(new FileWriter(outputFile));
     
                for(TestCase testCase : testCases) {
                    System.out.println(testCase);
                    String testCase_id=testCase.getId();
                    String testCase_title=testCase.getTitle();
                    String testCase_url=testCase.getUrl();
                    String testCase_type=testCase.getType();
                    String testCase_message=testCase.getResultMessage();
                    writer.write("<h2>");
                    for (int i=0; i<testCase_id.length(); i++){
                        writer.write((byte)testCase_id.charAt(i));
                    }
                    writer.write("</h2>");
                    writer.newLine();
                    writer.write("Titel: ");
                    for (int i=0; i<testCase_title.length(); i++){
                        writer.write((byte)testCase_title.charAt(i));
                    }
                    writer.write("<br/><br/>");
                    writer.newLine();
                    writer.write("URL: ");
                    for (int i=0; i<testCase_url.length(); i++){
                        writer.write((byte)testCase_url.charAt(i));
                    }
                    writer.write("<br/><br/>");
                    writer.newLine();
                    writer.write("Type: ");
                    for (int i=0; i<testCase_type.length(); i++){
                        writer.write((byte)testCase_type.charAt(i));
                    }
                    writer.write("<br/><br/>");
                    writer.newLine();
                    writer.write("Message: ");
                    for (int i=0; i<testCase_message.length(); i++){
                        writer.write((byte)testCase_message.charAt(i));
                    }
                    writer.write("<br/><br/>");
                    writer.newLine();
                }
                
                writer.flush();
            } catch(IOException e) {
                e.printStackTrace();
            } finally {
                if(writer != null) {
                    try {
                        writer.close();
                    } catch(IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
     
        private final class TestCase
        {
            private final String name;
            private final int countSuccess;
            private final int countNotSuccess;
     
            /**
             * @param name
             * @param countSuccess
             * @param countNotSuccess
             */
            public TestCase(String name, int countSuccess, int countNotSuccess) {
                this.name = name;
                this.countSuccess = countSuccess;
                this.countNotSuccess = countNotSuccess;
            }
     
            /**
             * @return the name
             */
            public String getName() {
                return name;
            }
     
            /**
             * @return the countSuccess
             */
            public int getCountSuccess() {
                return countSuccess;
            }
     
            /**
             * @return the countNotSuccess
             */
            public int getCountNotSuccess() {
                return countNotSuccess;
            }
        }
    }
    Geändert von Fabio Hellmann (11.08.11 um 07:54 Uhr)
     

  3. #18
    genodeftest genodeftest ist offline Mitglied Brillant
    Registriert seit
    Jun 2009
    Beiträge
    870
    Code bitte in Java-Tags (siehe meine Signatur), das erhöht die Lesbarkeit!
     
    Code bitte so einfügen: [java]System.out.println("Hallo");[/java] (Analog für andere Programmiersprachen)
    Code java:
    1
    
    System.out.println("Hallo");
    hilfreich zu Java: Really Big Index, Java ist auch eine Insel Band 1 und Band 2.
    ___________
    Ubuntu Bug #1: Microsoft has a majority market share
    Casecon: Projekt leiser Käse

Ähnliche Themen

  1. Length eines Strings
    Von Olaf Lehmann im Forum .NET Windows Forms
    Antworten: 2
    Letzter Beitrag: 17.07.10, 15:39
  2. Zeilenausgabe eines Strings
    Von Benzol im Forum PHP
    Antworten: 4
    Letzter Beitrag: 25.02.06, 16:30
  3. Teile eines Strings
    Von duermer im Forum Java
    Antworten: 1
    Letzter Beitrag: 30.10.04, 18:04
  4. ausschneiden eines strings
    Von ChuloGT im Forum PHP
    Antworten: 3
    Letzter Beitrag: 20.10.04, 16:33
  5. Verschlüsseln eines Strings(XOR)
    Von mowl im Forum C/C++
    Antworten: 15
    Letzter Beitrag: 25.04.04, 13:13