Have you wondered if you have to write unit tests for private methods of a class? In this post, I’ll answer that question for you.
This question is answered with the context of WordPress in mind. But this serves as a general rule, irrespective of the language.
I fell in love, once again, with WordPress so much that I started contributing to few open source projects.
I began my contribution by fixing small bugs. Lately, when I was writing test cases for a WordPress plugin, I had this question, “Should we write unit test case(s) for the private methods of a class?”
I didn’t have an answer for a moment, but then I figured that the private methods are used by the public methods. By writing test cases for the public methods of a class, we cover testing the functionality of the private methods. So the answer my question is ‘No, we don’t have to write unit tests for private methods of a class’.
What Should You Do If A Private Method Warrants Testing?
Even after covering the public method that uses the private method, if your private method warrants test to cover, then you should probably think of breaking the private method into smaller units. The basic rule is that a function must do only one specific thing.
In order to verify my understanding, I did a quick Google search and found that Brian, a software developer, had mentioned the same in his blog.
In this session, the speaker enlightened on the following.
Power BI building blocks- Datasets, Reports and Dashboards
Hierarchy between Datasets, Reports and Dashboards
Creating a sample report
How to save a report?
Power BI Building Blocks
Power BI has three building blocks namely the dataset, report and dashboard. You can understand the hierachy between these building blocks from the following definitions.
A dataset represents a single source of data that you connect or import into Power BI. Dataset holds the information of the data source and the information required to connect, like credentials. A dataset once created can be used in multiple reports.
A report in Power BI is intended to represent data using visualization such as charts and graphs. In order to create a report, data is required. We can import or connect to data using datasets.
Reports can be manually created by using datasets. Or, Power BI automatically creates reports for you when you connect to online services (through service content packs). Power BI desktop lets you create reports by combining different data sources.
Content pack is a simple way to organize and package datasets, reports and dashboards together into a single entity.
Signing up for Power BI (assuming you don’t have a Power BI account)
Connecting to a data source
Creating a simple report
Sign up for Power BI: You can easily sign up for Power BI by heading to PowerBI.com. All you need is an Organization email address to get started with Power BI. Email address from email service providers like Gmail, Yahoo, Outlook, etc. cannot be used to create an account with PowerBI.com.
Connect to data source: In order to create a report, we need data. The speaker used the data from the samples provided by PowerBI and I’ll be using the same. If you wish to follow along, you can find the samples in the Welcome screen. We will be using the Retail Analysis sample. You can learn more about the sample here.
Create a simple report: The Retail Analysis sample is a content pack that contains the dataset, report and dashboard. You need to understand the data to create reports and to draw insights with your data.
The Retail Analysis sample focuses on sales data and compares metrics such as sales, new stores, margin, etc. between the current year and the previous last year.
Let us create a couple of reports and pin a few on to a dashboard.
Step 01: Click on the dataset using which you want to create a report.
Step 02: You will see a blank canvas with Visualizations and Fields windows on the right sidebar.
Step 03: We shall create a simple table report to compare total units sold last year and this year each month during the fiscal year. In order to do that, drag and drop the Fiscal Month field from the Time sheet on to the blank white canvas. By default, PowerBI creates a table visualization when you drag and drop a column from the Fields window.
Step 04: Drag and drop Total Units Last Year and Total Units This Year columns over the table report created earlier. PowerBI automatically udpates the values based on the Fiscal Month that you placed on the canvas earlier. The Visualization windows lets you to gain more control and allows you to change and format the visualizations.
Step 05: You can save the report by click on the Save button. Once you save the report, you can find it under the Reports section. The yellow asterisk indicates that you have created the report recently. This behaviour is applicable for datasets and dashboards.
I have created an additional report page and few other visualizations other than the table visualization.
Step 06: Now, let us pin the report the to a dashboard.
To pin a visualization to a dashboard, hover over any visualization and you will find the ‘pin’ icon. Click on the pin icon and you can pin it to either a new or an existing dashboard. That’s it. This way you can pin visualizations that are in the similar context to present data in a meaningful way.
We now have successfully created a report, learnt how to pin reports to a dashboard and also learnt to save reports.
The speaker also demonstrated how to create reports in Power BI Desktop and upload it to the Power BI service. You can learn more about that from the Power BI documentation portal.