2016년 12월 1일 목요일

Junit MultiThread Test code


import org.junit.Test;

import junit.framework.TestCase;
import net.sourceforge.groboutils.junit.v1.MultiThreadedTestRunner;
import net.sourceforge.groboutils.junit.v1.TestRunnable;

public class TestThread extends TestCase{
 
 private static int THREAD_SIZE = 20;
 
 /*
  * Test class should have exactly one public zero-argument constructor이므로
  * TestCase 클래스를 extends 하고 GroboUtils의 클래스인 TestRunnable을 상속받은 클래스를 이너클래스로 사용하였다.
  */
 
 public class MultiThreadTest extends TestRunnable {
  
  private int i = 0;
  
  
  public MultiThreadTest(int i){
   this.i = i;
  }
  
  @Override
  public void runTest() throws Throwable {
   Thread.sleep(1000);
   
   System.out.println(Thread.currentThread().getName() + " : [" + i + "]");
  }
 }
 
 @Test
 public void test() throws Throwable{
  TestRunnable[] t = new TestRunnable[THREAD_SIZE];
  
  for(int index=0; index < THREAD_SIZE; index++){
   t[index]=new MultiThreadTest(index);
  }
  
  MultiThreadedTestRunner mttr = new MultiThreadedTestRunner(t);
  mttr.runTestRunnables();
  
  System.out.println("main end.........................");
 }
}

2016년 9월 29일 목요일

Windows 환경에서 Python Selenium 설치

precodition : python3.5 설치 및 path 설정

(1) python selenium 라이브러리 설치


C:\PYTHON_HOME\..\Scripts
pip install -U selenium
실행 시 SSL 오류가 발생하였음

 Could not fetch URL https://pypi.python.org/simple/selenium/: There was a problem confirming the ssl certificate: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:645) - skipping
  Could not find a version that satisfies the requirement selenium (from versions: )
No matching distribution found for selenium

[해결방안]

  1. pip upgrade(pip 버전 확인 pip --version)
  2. easy_install pyopenssl 실행
  3. pip install --upgrade --trusted-host pypi.python.org selenium








출처 : http://selenium-python.readthedocs.io/installation.html


Python if __name__ == "__main__" 정리, 설명

if __name__ == "__main__" 의미
파이썬에서 일반적으로 import 방식으로 다른 코드를 불러오는데, 파이썬이 스크립트 언어이기에 그때마다 불려온 파일에 있는 메소드와 클래스를 실행 시킨다면 원하는대로 사용하기가 힘들기에

if __name__ == "__main__" 구문을 통해 실행될 코드와 그냥 참조 대기상태로 존재할 코드를 구분할 수 있다.
__name__ 은 보통 해당 파일의 위치+이름으로 구성돼있다.
from django import db의 경우 db.__name__을 찍어보면 'django.db'가 나온다.

test.py

def say_hi():

    print("Hi")



if __name__=="__main__":

    say_hi()
test.py 파일을 python test.py 로 실행한다면 say_hi() 메소드가 실행된다. 직접 실행되는 파일의 __name__은 __main__으로 설정된다.
그러나 다른 파일에서 import test 로 위 파일을 불러온다면 say_hi()는 실행되지 않는다. 기본적으로 test.py의 __name__ 은 그냥 'test'이다. (파일명)

2016년 1월 5일 화요일

jar 파일을 자신의 로컬 레포지토리에 등록하는 방법

mvn install:install-file -Dfile=c:\kaptcha-2.3.jar -DgroupId=com.google.code -DartifactId=kaptcha -Dversion=2.3 -Dpackaging=jar

인스톨 한 후 pom.xml에 dependency 걸어주면 된다.