Excel-DNA / Excel-DNA/DeveloperTools

Testing - open a testing workbook

Aperta
#10 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
C#
Stelle
0
Fork
2
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

I think it would be nice to be able to run all the test from a class in the context of a pre-created workbook.
I'm trying to understand what the xUnit way to set this up would be.

For example, in the `XFunctions` add-in, I have some example workbooks:
https://github.com/Excel-DNA/XFunctions/tree/master/Examples
I want to make tests for the XFunctions add-in that execute in the context of one of those workbooks.

I suggest we add a `WorkbookFixture` class in the `ExcelDna.Testing` assembly that looks like this:

```
public class WorkbookFixture : IDisposable
{
public Workbook Workbook { get; }

public WorkbookFixture(string name)
{
// Look for the workbook in the test directory or somewhere close
// not sure what the path search story should be - do we allow partial paths like testbook/myBook.xlsx ?
// in practise one might want the test workbook in the test project directory, not the test output directory?
// Anyway, once we've found it we open it.
}
public Dispose() { // Close it? }
}
```

For the test code, maybe something like this could then work.

Suppose there is a file called `HelpExamples.xlsx` in a good directory.
Then the test gets a class that subclasses the WorkbookFixture, passing in the name as constructor parameter.

```
public class HelpExamplesFixture : base("HelpExamples.xlsx") {}

public class HelpExampleTests : IClassFixture
{

Workbook _wb;

public HelpExampleTests(HelpExamplesFixture fixture) { _wb = fixture.Workbook; };

[Fact]
public void CheckSomething()
{
Assert.Equal(_wb.Range["A1"], 123);
}
}
```

@Sergey-Vlasov Do you have any thoughts on how this should work?

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.