001/** 002 * Powerunit - A JDK1.8 test framework 003 * Copyright (C) 2014 Mathieu Boretti. 004 * 005 * This file is part of Powerunit 006 * 007 * Powerunit is free software: you can redistribute it and/or modify 008 * it under the terms of the GNU General Public License as published by 009 * the Free Software Foundation, either version 3 of the License, or 010 * (at your option) any later version. 011 * 012 * Powerunit is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 015 * GNU General Public License for more details. 016 * 017 * You should have received a copy of the GNU General Public License 018 * along with Powerunit. If not, see <http://www.gnu.org/licenses/>. 019 */ 020package ch.powerunit; 021 022import java.io.PrintStream; 023import java.util.Arrays; 024 025import ch.powerunit.impl.DefaultPowerUnitRunnerImpl; 026import ch.powerunit.impl.DefaultTestResultListener; 027 028/** 029 * Main class that can be used to run test. 030 * 031 * @author borettim 032 * @since 0.1.0 033 * @see #main(String[]) The main method to have the description of the 034 * parameters. 035 */ 036public class PowerUnitMainRunner { 037 038 private PowerUnitMainRunner() { 039 } 040 041 public static final PrintStream DEFAULT_OUT = System.out; 042 043 /** 044 * The main method. 045 * 046 * @param args 047 * The argument syntax is the following : 048 * <ul> 049 * <li><code>path className,...</code></li> 050 * </ul> 051 */ 052 public static void main(String[] args) { 053 if (args.length != 2) { 054 DEFAULT_OUT.printf("The received argument is not valid : %1$s%n", 055 Arrays.toString(args)); 056 System.exit(-1);// NOSONAR 057 } 058 String outputPath = args[0]; 059 String classes[] = args[1].split("\\s*,\\s*"); 060 StringBuilder resumedSucess = new StringBuilder(); 061 StringBuilder resumedFailure = new StringBuilder(); 062 StringBuilder resumedSkipped = new StringBuilder(); 063 064 boolean success = true; 065 for (String c : classes) { 066 DEFAULT_OUT.printf("Running test for %1$s%n", c); 067 try { 068 Class<?> cls = Class.forName(c); 069 PowerUnitRunner r = new DefaultPowerUnitRunnerImpl(cls); 070 DefaultTestResultListener def = new DefaultTestResultListener( 071 outputPath, DEFAULT_OUT); 072 r.addListener(def); 073 r.run();// NOSONAR 074 success &= !def.isError(); 075 resumedSucess.append(def.getResumedSucess()); 076 resumedFailure.append(def.getResumedFailure()); 077 resumedSkipped.append(def.getResumedSkipped()); 078 } catch (ClassNotFoundException e) { 079 DEFAULT_OUT.printf("Unable to create the class %1$s%n", c); 080 } finally { 081 DEFAULT_OUT.printf("End running test for %1$s%n", c); 082 } 083 } 084 DEFAULT_OUT.print("\n\nSuccess tests:\n" + resumedSucess.toString() 085 + "\n\nSkipped tests:\n" + resumedSkipped.toString() 086 + "\n\nFailed tests:\n" + resumedFailure.toString() + "\n"); 087 if (!success) { 088 System.exit(-1);// NOSONAR 089 } 090 System.exit(0);// NOSONAR 091 } 092 093}