[seasar-dotnet:875] Re: [S2Unit.NET][要望]テストクラス単位でdiconファイルを指定したい
Hiroaki Fujii
[E-MAIL ADDRESS DELETED]
2008年 6月 11日 (水) 13:27:20 JST
上谷さん。
藤井です。
昨晩はおバカなアドバイスをして申し訳ありません。
下記で対応できると思います。
・各テストクラスのSetUpメソッドでテストクラス用のdiconファイルを
Includeする。こうすればフィールドも初期化される。
・app.configで指定したdiconファイルの中は空でよい。
SetUpメソッドですが、ドキュメント
http://s2container.net.seasar.org/ja/s2unit.html#init
にも記載されていますが、下記のとおりソースを書きました。
[TestFixture]
public class TestDepartment : S2TestCase
{
private string _abc = null;
///
/// MbUnit用初期化
///
[SetUp]
public void Setup()
{
FileInfo info = new FileInfo(
string.Format("{0}.dll.config", SystemInfo.AssemblyShortName(
Assembly.GetExecutingAssembly())));
// アセンブリがdllの場合は".dll.config"
XmlConfigurator.Configure(LogManager.GetRepository(), info);
}
/// <summary>
/// クラスの初期化処理
/// </summary>
public void SetUp()
{
Include("Department.dicon");
}
[Test, S2]
public void TestFields()
{
Assert.AreEqual("hoge", _abc);
}
}
> ただ、1つのテストクラスのメソッドすべてにIncludeを書くことになり、
> あまりスマートじゃないな、ということで今回の要望に至っています。
確かに、そのとおりです。
ReSharperのTemplate機能を使っていたので、メソッドごとに書くことに
まったく疑問に思っていませんでした。楽なツールを使うとダメですね。
また、
> あと、確認なんですが、IParent がIChildをプロパティに持つとき、
> 下記のIncludeTest、InitTest、RegisterTestが失敗するのは仕様でしょう
> か?
については、後でご返事します。
よろしくお願いします。
Toru Uetani さんは書きました:
> 藤井さん、おはようございます。上谷です。
>
>> テストクラスの中で、そのクラス用の別のdiconファイルを指定してあげて、
> すいません、ちょっとこの意味がわかりません。
> テストメソッドの中で、this.Includeを実行するということでしょうか?
> 現状その方法も使っております。
> ただ、1つのテストクラスのメソッドすべてにIncludeを書くことになり、
> あまりスマートじゃないな、ということで今回の要望に至っています。
>
>> _abc = (string) GetComponent("abc");
>> Assert.AreEqual("hoge", _abc, "abc");
>> こうしてあげると、そのテストクラス用のdiconファイルに記述した値が
>> セットされます。
>> これではだめでしょうか?
> 今のところ、その方法でテストしております。
> が、これだとS2Unitを使ってる意味があるのかな・・・と。
>
>
> あと、確認なんですが、IParent がIChildをプロパティに持つとき、
> 下記のIncludeTest、InitTest、RegisterTestが失敗するのは仕様でしょうか?
>
> --App.dicon
> <components>
> <component class="Foo.Fuga.Parent"></component>
> </components>
>
> --App2.dicon
> <components>
> <component class="Foo.Fuga.Child"></component>
> </components>
>
> --App3.dicon
> <components>
> <include path="Foo.Fuga.App2.dicon" />
> <component class="Foo.Fuga.Parent"></component>
> </components>
>
> --Test.cs
> namespace Foo.Fuga {
> [TestFixture]
> public class Test : S2TestCase {
> private IParent _parent = null;
> private IChild _child = null;
>
> [S2, Test]
> public void AutoBindingTest() {
> this.Include("App2.dicon");
> Assert.IsNotNull(_parent);
> Assert.IsNotNull(_child);//ここで失敗
> }
>
> [S2,Test]
> public void IncludeTest() {
> this.Include("App2.dicon");
> IParent parent = (IParent)this.GetComponent(typeof(IParent));
> IChild child = (IChild)this.GetComponent(typeof(IChild));
> Assert.IsNotNull(parent);
> Assert.IsNotNull(child);
> Assert.IsNotNull(parent.Hoge);//ここで失敗
> }
>
> [S2, Test]
> public void InitTest() {
> this.Container.Destroy();
> this.Container.Path = "Foo.Fuga.App3.dicon";
> this.Container.Init();
>
> IParent parent = (IParent)this.GetComponent(typeof(IParent));
> IChild child = (IChild)this.GetComponent(typeof(IChild));//ここで失敗
> Assert.IsNotNull(parent);
> Assert.IsNotNull(child);
> Assert.IsNotNull(parent.Hoge);
> }
>
> [S2, Test]
> public void RegisterTest() {
> this.Register(new Child());
> IParent parent = (IParent)this.GetComponent(typeof(IParent));
> IChild child = (IChild)this.GetComponent(typeof(IChild));
> Assert.IsNotNull(parent);
> Assert.IsNotNull(child);
> Assert.IsNotNull(parent.Hoge);//ここで失敗
> }
> }
> }
>
> --
> ┏┏┏┏┏┏┏┏┏┏┏┏┏┏┏┏┏┏┏┏┏┏┏┏┏┏┏┏┏
>
> ┏━━━┓ 上谷 徹(Toru Uetani)
> ┃\_/┃ mail:[E-MAIL ADDRESS DELETED]
> ┗━━━┛
> ┏┏┏┏┏┏┏┏┏┏┏┏┏┏┏┏┏┏┏┏┏┏┏┏┏┏┏┏┏
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> seasar-dotnet mailing list
> [E-MAIL ADDRESS DELETED]
> https://ml.seasar.org/mailman/listinfo/seasar-dotnet
seasar-dotnet メーリングリストの案内