2012-03-11 2 views
1

を使用すると、テスト構成でDeploymentを実行すると、ユニットテストが実行されるたびにコピーが作成されますが、時間がかかります。データは、ビルド後にのみ変更されるビットマップの束です。単体テスト用に大きなデータを展開する場所は?

このような大規模なテストデータを展開するための規約は何ですか?

+1

あなたはユニットテストを書いているようにそれが聞こえない、それが鳴りますが、機能や統合テストを書いているように... – Nix

+0

を私はユニットテストしていますアルゴリズム。これは正しい用語ではありませんか? – Leo

+0

私は間違っているかもしれませんが、テストを実行するために大きなデータセットをロードする必要がある理由の詳細をもっと説明したいと思うかもしれません。ファイル、データベースなどのデータの種類を説明します。これは、より正確で正確な回答を提供するのに役立ちます。 – Nix

答えて

1

ここでは、ファイルの依存関係とテストについてのブログ記事を書きました。

http://tsells.wordpress.com/2012/03/06/how-to-run-integration-tests-with-file-dependencies/

ファイルシステムしようとしているので、あなたが行っているテストは、統合テストです。私はあなたが達成しようとしているもののためのポストのクラスごとのメソッドの例を使用します。ポストの

内容

免責

多くの場合、開発者テストは、ファイルシステム上に存在する必要があるファイルの特定のファイル/セットで実行する必要があります。多くの「純粋主義者」は、これが悪い考えであると考えています。あなたは、これが必須ではない方法であなたのシステムを "模倣"すべきです。場合によっては真実かもしれませんが、私は「現実主義者」であり、このようなことを行うための複雑さの要件は、テストのためにファイルシステムを利用することによる利点をはるかに上回ることがあります。しかし、これはテストを真の「ユニット」テストから「統合」テストに移行させます。私はこれに満足しています。統合テストは単体テストよりも価値が高いと私は信じています。セットアップが適切な方法で実行されている場合、このテストはVisual Studio、MSビルド、コマンドライン、Team Cityなどのビルドエージェントを実行するビルドサーバーでローカルで実行できます。

あなたはここにソースコードをダウンロードすることができます。このテスト

テストランナー(それは私がラインだけでなく、デバッグで実行することができますように私はTestDriven.Netを使って好きな)のためのTestClass.zip

要件。 IDisposableを実装できるsystem.IO関数の一部をラップするファイルクラス。これは、一度有効範囲外の「サンドボックス」を作成するのに便利です。また、使用される一時ファイルを削除して、クリーンアップが自動的に行われます(サンプルクラスがサンプルに添付されています)。 NUnitまたはMSTest。私はまだNUnitを好む。 使用オプション テストファイルを使用するための要件によって、ファイルを設定してクリーンアップ(削除)する方法と時期が決まります。 1試験あたり

- ファイルはそれらに対するテスト実行 毎のテストクラスごとに再生されます - ファイルがFileSandBoxクラスはファイルが生活するための一時的な場所を作成するために使用され、その後削除され、両方の事例では、一度テストクラス ごとに生成されます一度テストが完了すると。クラスの使用当たり

[TestFixture] パブリッククラスPerClass {プライベートFileSandboxの_sandbox。 プライベート文字列_tempFileLocation;テストの使用(オプション1)試験の使用当たり

[TestFixture] 
public class PerTest 
{ 
    public PerTest(){} 

    /// <summary> 
    /// Setup class - runs once per class 
    /// </summary> 
    [TestFixtureSetUp] 
    public void SetupClass() 
    { 
     // NOOP 
    } 

    /// <summary> 
    /// Tear down class (cleanup) 
    /// </summary> 
    [TestFixtureTearDown] 
    public void TearDownClass() 
    { 
     // NOOP 
    } 

    [Test, Description("Testing doing something with files on the filesystem")] 
    public void MyFileSystemTest() 
    { 
     using (FileSandbox sandbox = new FileSandbox()) 
     { 
      // Getting Temp file name to use 
      string tempfile = sandbox.GetTempFileName("txt"); 
      // Get the current executing assembly (in this case it's the test dll) 
      Assembly myassembly = Assembly.GetExecutingAssembly(); 
      // Get the stream (embedded resource) - be sure to wrap in a using block 
      using (Stream stream = myassembly.GetManifestResourceStream("TestClass.TestFiles.TextFile1.txt")) 
      { 
       // In this case using an external method to write the stream to the file system 
       tempfile = TestHelper.StreamToFile(stream, tempfile); 
       string[] lines = File.ReadAllLines(tempfile); 
       Assert.IsTrue(lines.Length > 0); 
      } 
     } 
    } 
} 

(オプション2)

[TestFixture] パブリッククラスPerEachTest {プライベートFileSandboxの_sandbox当たり

public PerClass() {} 

    /// <summary> 
    /// Setup class - runs once per class 
    /// </summary> 
    [TestFixtureSetUp] 
    public void SetupClass() 
    { 
     _sandbox = new FileSandbox(); 

     // Getting Temp file name to use 
     _tempFileLocation = _sandbox.GetTempFileName("txt"); 
     // Get the current executing assembly (in this case it's the test dll) 
     Assembly myassembly = Assembly.GetExecutingAssembly(); 
     // Get the stream (embedded resource) - be sure to wrap in a using block 
     using (Stream stream = myassembly.GetManifestResourceStream("TestClass.TestFiles.TextFile1.txt")) 
     { 
      // In this case using an external method to write the stream to the file system 
      _tempFileLocation = TestHelper.StreamToFile(stream, _tempFileLocation); 
     } 
    } 

    /// <summary> 
    /// Tear down class (cleanup) 
    /// </summary> 
    [TestFixtureTearDown] 
    public void TearDownClass() 
    { 
     _sandbox.Dispose(); 
    } 

    [Test, Description("Testing doing something with files on the filesystem")] 
    public void MyFileSystemTest() 
    { 
     string[] lines = File.ReadAllLines(_tempFileLocation); 
     Assert.IsTrue(lines.Length > 0); 
    } 
} 

。 プライベート文字列_tempFileLocation;

public PerEachTest() { } 

    /// <summary> 
    /// Setup class - runs once per class 
    /// </summary> 
    [TestFixtureSetUp] 
    public void SetupClass() 
    { 
     // NOOP 
    } 

    /// <summary> 
    /// Tear down class (cleanup) 
    /// </summary> 
    [TestFixtureTearDown] 
    public void TearDownClass() 
    { 
     // NOOP 
    } 

    [SetUp] 
    public void Setup() 
    { 
     _sandbox = new FileSandbox(); 

     // Getting Temp file name to use 
     _tempFileLocation = _sandbox.GetTempFileName("txt"); 
     // Get the current executing assembly (in this case it's the test dll) 
     Assembly myassembly = Assembly.GetExecutingAssembly(); 
     // Get the stream (embedded resource) - be sure to wrap in a using block 
     using (Stream stream = myassembly.GetManifestResourceStream("TestClass.TestFiles.TextFile1.txt")) 
     { 
      // In this case using an external method to write the stream to the file system 
      _tempFileLocation = TestHelper.StreamToFile(stream, _tempFileLocation); 
     } 
    } 

    [TearDown] 
    public void Teardown() 
    { 
     _sandbox.Dispose(); 
    } 

    [Test, Description("Testing doing something with files on the filesystem")] 
    public void MyFileSystemTest() 
    { 
     string[] lines = File.ReadAllLines(_tempFileLocation); 
     Assert.IsTrue(lines.Length > 0); 
    } 
} 

あなたはここにソースコードをダウンロードすることができます:Source Code

+0

別のもの - 私はあなたのイメージをzipファイルとして保存します - ファイルを場所(temp)にコピーし、そこから抽出して使用します。それぞれのファイルを個別にコピーするよりもはるかに高速に動作します。 – tsells

関連する問題