2011-08-02 5 views
3

나는 파일 시스템을 만질 필요가있는 코드를보다 쉽게 ​​단위 테스트 할 수 있도록 파일 시스템 래퍼로 commons-vfs를 사용하려고한다. 지금은 API에 익숙해지고 있습니다. 내가하고 싶은 것은 가상 파일 시스템을 만들고 두 개의 파일 (폴더와 루트에있는 파일)을 추가하는 것이다.Commons-vfs 파일 시스템을 조롱하다

[junit] Testcase: testCreationOfChildrenFiles(com.usengineeringsolutions.bridgewatch.vfs.CommonsVfsLearningSpikeTest):  Caused an ERROR 
[junit] Incorrect file system URI "file:///" in name "file:///rootVfs/childFolder", was expecting "/rootVfs/". 
[junit] org.apache.commons.vfs.FileSystemException: Incorrect file system URI "file:///" in name "file:///rootVfs/childFolder", was expecting "/rootVfs/". 
[junit]  at org.apache.commons.vfs.provider.AbstractFileSystem.resolveFile(AbstractFileSystem.java:274) 
[junit]  at org.apache.commons.vfs.provider.AbstractFileSystem.resolveFile(AbstractFileSystem.java:267) 
[junit]  at org.apache.commons.vfs.provider.AbstractFileObject.resolveFile(AbstractFileObject.java:670) 
[junit]  at com.usengineeringsolutions.bridgewatch.vfs.CommonsVfsLearningSpikeTest.testCreationOfChildrenFiles(CommonsVfsLearningSpikeTest.java:27) 
[junit] 
[junit] 

답변

1

난 그냥 시작했습니다 : 현재 나는 다음과 같은 오류를 받고 있어요

public class CommonsVfsLearningSpikeTest extends Base { 
FileSystemManager fsManager; 
FileObject rootVFS; 

@Before public void createFixture() throws Exception{ 
    this.fsManager = VFS.getManager(); 
    this.rootVFS = fsManager.createVirtualFileSystem("rootVfs"); 
} 

@Test public void testCreationOfDefaultFileSystem() throws Exception { 
    assertNotNull(fsManager); 
} 

@Test public void testCreationOfVFS() throws Exception { 
    //root file has an empty base name 
    assertEquals("", rootVFS.getName().getBaseName()); 
} 

@Test public void testCreationOfChildrenFiles() throws Exception { 
    FileObject childFolder = rootVFS.resolveFile("childFolder"); 
    childFolder.createFolder(); 
    assertNotNull(childFolder); 

    FileObject childFile = rootVFS.resolveFile("childFolder/childFile"); 
    childFile.createFile(); 
    assertNotNull(childFile); 

} 

}

: 여기

내가 API를 testdrive하기 위해 작성한 테스트 클래스의 vfs를 사용하고 vfs에 의존하는 구성 요소에 대한 단위 테스트에서 VFS 인터페이스를 완전히 조롱하지 않고 "ram : //"파일 시스템을 사용하는 방법을 택했습니다.

이것은 테스트 동작이 이제는 SUT (테스트중인 피험자) 이상에 의존하기 때문에 더 이상 "순수"하지 않다는 것을 의미합니다.하지만 그것은 타당한 결과를 얻으려는 타협이었습니다. 일.

관련 문제