ExcelDna.Testing Plug-in

71 views
Skip to first unread message

Umer Waheed

unread,
Apr 4, 2022, 2:43:05 PM4/4/22
to Excel-DNA
Hello,

I have developed a excel plug-in using Excel DNA. This plug-in has a ribbon that contains login and other actions where user can select the column name, cell, rows etc and perform the action. The plug-in will call some API and get the data and update the excel selected row, column or cell. It is working perfectly.

Now, I want to write integration tests for this plug-in. I tried to open excel template and I want to hold until user click the button and then after plugin update the sheet then run my Asserts. Is it possible to do it?

Regards,
Umer Waheed

Govert van Drimmelen

unread,
Apr 4, 2022, 4:46:40 PM4/4/22
to exce...@googlegroups.com
Hi Umer,

Have you found the testing tutorial and video here https://github.com/Excel-DNA/Tutorials/tree/master/Testing

Testing the ribbon user interface can be a bit tricky. If you are running the tests in-process you might be able to invoke the ribbon methods directly, then check the results. So your test would not be waiting for actual user interaction, but faking it in a sense.

-Govert



--
You received this message because you are subscribed to the Google Groups "Excel-DNA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to exceldna+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/exceldna/3f8aee5c-ba2f-40bb-a19d-9c5bfc3fba09n%40googlegroups.com.

Umer Waheed

unread,
Apr 4, 2022, 5:56:52 PM4/4/22
to exce...@googlegroups.com
Appreciated your response.

I have already gone through the video and test sample project. It helped but my case is different. My tests are in process. When I run the test, before clicking ribbon button the test executed. Tye ribbon action may take 1-2 minutes to complete action.

Also, with visual studio 2019 it throws error about xunit.running.utiliyu but works fine with 2022. I have a excel template for testing and when I load that particular file. It just open blank excel file instead of my file.

Regards, 
Umer Waheed 

Craig Crevola

unread,
Apr 4, 2022, 6:42:37 PM4/4/22
to exce...@googlegroups.com
Hi Umer,

WinAppDriver might be suitable if you want to test using UI. https://github.com/microsoft/WinAppDriver

Thanks 

Craig. 

Umer Waheed

unread,
Apr 6, 2022, 12:42:21 PM4/6/22
to exce...@googlegroups.com
I'm facing an issue when I run the tests in Visual Studio 2019. It says:
image.png

In Visual studio 2022, it runs fine but the unit test with  [ExcelFact(Workbook = "Test.xlsx")] does not open desired sheet. I know recommended in 2019 but in 2019 the above issue happened. 

I have looked in bin, xunit.runner.utility.net45 is there but why it looks for xunit.runnier.utility.net35?

REgards,
Umer Waheed

Govert van Drimmelen

unread,
Apr 11, 2022, 5:54:35 PM4/11/22
to Excel-DNA
Hi Umer,

I expect that the ExcelDna.Testing extension should work fine with Visual Studio 2022.
Sometimes having the right test running in place can be tricky.

I'll try to check again that everything works fine on my machine - if it does we can figure out if something is different on your side, else see what needs to be fixed.

-Govert

Sergey Vlasov

unread,
Apr 16, 2022, 1:53:05 PM4/16/22
to Excel-DNA

Umer,

 

It is possible with ExcelDna.Testing to open an excel template, click the ribbon button and then after plugin update the sheet run asserts.

 

I've created a sample solution (attached) that demonstrates it.

 

The main ribbon code is:

 

        public void OnButtonPressed(IRibbonControl control)

        {

            Application app = (Application)ExcelDnaUtil.Application;

            var ws = app.ActiveSheet;

            ws.Range["A3"].Value = 22;

        }

 

        public void OnButtonAsyncPressed(IRibbonControl control)

        {

            Application app = (Application)ExcelDnaUtil.Application;

            var ws = app.ActiveSheet;

 

            ExcelAsyncUtil.QueueAsMacro(async () =>

            {

                await Task.Delay(2000);

                ws.Range["A4"].Value = 33;

            });

        }

 

And testing code is:

 

using ExcelDna.Testing;

using Xunit;

 

[assembly: Xunit.TestFramework("Xunit.ExcelTestFramework", "ExcelDna.Testing")]

 

namespace MyAddIn.Test

{

    [ExcelTestSettings(AddIn = @"..\..\..\MyAddIn\bin\Debug\MyAddIn-AddIn", Workbook = "Book.xlsx")]

    public class Tests

    {

        [ExcelFact]

        public void WorkbookData()

        {

            var ws = Util.Workbook.Sheets[1];

            Assert.Equal(3, ws.Range["A2"].Value);

        }

 

        [ExcelFact]

        public void Ribbon()

        {

            Automation.ClickRibbonButton("ExampleAddin", "My Button");

 

            var ws = Util.Workbook.Sheets[1];

            Assert.Equal(22, ws.Range["A3"].Value);

        }

 

        [ExcelFact]

        public void RibbonAsync()

        {

            Automation.ClickRibbonButton("ExampleAddin", "My Button Async");

 

            var ws = Util.Workbook.Sheets[1];

            Automation.WaitFor(() => ws.Range["A4"].Value == 33, 3000);

            Assert.Equal(33, ws.Range["A4"].Value);

        }

    }

}

 

On my machine it works both in VS 2019 and VS 2022.

 

When testing the extracted solution code from .zip I saw an error about xunit.runner.utility similar to yours (though for me it was for v452). It required to restart VS and rebuild to fix this problem. I assume it relates to packages restore.

 

Please try the attached solution on your machine.

testing.zip
Reply all
Reply to author
Forward
0 new messages